mirror of https://github.com/status-im/consul.git
test: move discover tests
This commit is contained in:
parent
d2ee591fbf
commit
9ceef2b32e
|
@ -352,101 +352,6 @@ func TestRetryJoinWanFail(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDiscoverEC2Hosts(t *testing.T) {
|
||||
t.Parallel()
|
||||
if os.Getenv("AWS_REGION") == "" {
|
||||
t.Skip("AWS_REGION not set, skipping")
|
||||
}
|
||||
|
||||
if os.Getenv("AWS_ACCESS_KEY_ID") == "" {
|
||||
t.Skip("AWS_ACCESS_KEY_ID not set, skipping")
|
||||
}
|
||||
|
||||
if os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
|
||||
t.Skip("AWS_SECRET_ACCESS_KEY not set, skipping")
|
||||
}
|
||||
|
||||
c := &Config{
|
||||
RetryJoinEC2: RetryJoinEC2{
|
||||
Region: os.Getenv("AWS_REGION"),
|
||||
TagKey: "ConsulRole",
|
||||
TagValue: "Server",
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := c.discoverEc2Hosts(&log.Logger{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(servers) != 3 {
|
||||
t.Fatalf("bad: %v", servers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverGCEHosts(t *testing.T) {
|
||||
t.Parallel()
|
||||
if os.Getenv("GCE_PROJECT") == "" {
|
||||
t.Skip("GCE_PROJECT not set, skipping")
|
||||
}
|
||||
|
||||
if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" && os.Getenv("GCE_CONFIG_CREDENTIALS") == "" {
|
||||
t.Skip("GOOGLE_APPLICATION_CREDENTIALS or GCE_CONFIG_CREDENTIALS not set, skipping")
|
||||
}
|
||||
|
||||
c := &Config{
|
||||
RetryJoinGCE: RetryJoinGCE{
|
||||
ProjectName: os.Getenv("GCE_PROJECT"),
|
||||
ZonePattern: os.Getenv("GCE_ZONE"),
|
||||
TagValue: "consulrole-server",
|
||||
CredentialsFile: os.Getenv("GCE_CONFIG_CREDENTIALS"),
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := c.discoverGCEHosts(log.New(os.Stderr, "", log.LstdFlags))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(servers) != 3 {
|
||||
t.Fatalf("bad: %v", servers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverAzureHosts(t *testing.T) {
|
||||
subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID")
|
||||
tenantID := os.Getenv("ARM_TENANT_ID")
|
||||
clientID := os.Getenv("ARM_CLIENT_ID")
|
||||
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
|
||||
environment := os.Getenv("ARM_ENVIRONMENT")
|
||||
|
||||
if subscriptionID == "" || clientID == "" || clientSecret == "" || tenantID == "" {
|
||||
t.Skip("ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET and ARM_TENANT_ID " +
|
||||
"must be set to test Discover Azure Hosts")
|
||||
}
|
||||
|
||||
if environment == "" {
|
||||
t.Log("Environments other than Public not supported at the moment")
|
||||
}
|
||||
|
||||
c := &Config{
|
||||
RetryJoinAzure: RetryJoinAzure{
|
||||
SubscriptionID: subscriptionID,
|
||||
ClientID: clientID,
|
||||
SecretAccessKey: clientSecret,
|
||||
TenantID: tenantID,
|
||||
TagName: "type",
|
||||
TagValue: "Foundation",
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := c.discoverAzureHosts(log.New(os.Stderr, "", log.LstdFlags))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(servers) != 3 {
|
||||
t.Fatalf("bad: %v", servers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProtectDataDir(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := testutil.TempDir(t, "consul")
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDiscoverAzureHosts(t *testing.T) {
|
||||
subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID")
|
||||
tenantID := os.Getenv("ARM_TENANT_ID")
|
||||
clientID := os.Getenv("ARM_CLIENT_ID")
|
||||
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
|
||||
environment := os.Getenv("ARM_ENVIRONMENT")
|
||||
|
||||
if subscriptionID == "" || clientID == "" || clientSecret == "" || tenantID == "" {
|
||||
t.Skip("ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET and ARM_TENANT_ID " +
|
||||
"must be set to test Discover Azure Hosts")
|
||||
}
|
||||
|
||||
if environment == "" {
|
||||
t.Log("Environments other than Public not supported at the moment")
|
||||
}
|
||||
|
||||
c := &Config{
|
||||
RetryJoinAzure: RetryJoinAzure{
|
||||
SubscriptionID: subscriptionID,
|
||||
ClientID: clientID,
|
||||
SecretAccessKey: clientSecret,
|
||||
TenantID: tenantID,
|
||||
TagName: "type",
|
||||
TagValue: "Foundation",
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := c.discoverAzureHosts(log.New(os.Stderr, "", log.LstdFlags))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(servers) != 3 {
|
||||
t.Fatalf("bad: %v", servers)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDiscoverEC2Hosts(t *testing.T) {
|
||||
t.Parallel()
|
||||
if os.Getenv("AWS_REGION") == "" {
|
||||
t.Skip("AWS_REGION not set, skipping")
|
||||
}
|
||||
|
||||
if os.Getenv("AWS_ACCESS_KEY_ID") == "" {
|
||||
t.Skip("AWS_ACCESS_KEY_ID not set, skipping")
|
||||
}
|
||||
|
||||
if os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
|
||||
t.Skip("AWS_SECRET_ACCESS_KEY not set, skipping")
|
||||
}
|
||||
|
||||
c := &Config{
|
||||
RetryJoinEC2: RetryJoinEC2{
|
||||
Region: os.Getenv("AWS_REGION"),
|
||||
TagKey: "ConsulRole",
|
||||
TagValue: "Server",
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := c.discoverEc2Hosts(&log.Logger{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(servers) != 3 {
|
||||
t.Fatalf("bad: %v", servers)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDiscoverGCEHosts(t *testing.T) {
|
||||
t.Parallel()
|
||||
if os.Getenv("GCE_PROJECT") == "" {
|
||||
t.Skip("GCE_PROJECT not set, skipping")
|
||||
}
|
||||
|
||||
if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" && os.Getenv("GCE_CONFIG_CREDENTIALS") == "" {
|
||||
t.Skip("GOOGLE_APPLICATION_CREDENTIALS or GCE_CONFIG_CREDENTIALS not set, skipping")
|
||||
}
|
||||
|
||||
c := &Config{
|
||||
RetryJoinGCE: RetryJoinGCE{
|
||||
ProjectName: os.Getenv("GCE_PROJECT"),
|
||||
ZonePattern: os.Getenv("GCE_ZONE"),
|
||||
TagValue: "consulrole-server",
|
||||
CredentialsFile: os.Getenv("GCE_CONFIG_CREDENTIALS"),
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := c.discoverGCEHosts(log.New(os.Stderr, "", log.LstdFlags))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(servers) != 3 {
|
||||
t.Fatalf("bad: %v", servers)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue