Add testing around EC2 discovery config

This commit is contained in:
Kyle Havlovitz 2016-11-01 18:20:23 -04:00
parent 0499784b94
commit d615141c16
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
2 changed files with 51 additions and 4 deletions

View File

@ -267,6 +267,10 @@ func TestRetryJoinWanFail(t *testing.T) {
} }
func TestDiscoverEC2Hosts(t *testing.T) { func TestDiscoverEC2Hosts(t *testing.T) {
if os.Getenv("AWS_REGION") == "" {
t.Skip("AWS_REGION not set, skipping")
}
if os.Getenv("AWS_ACCESS_KEY_ID") == "" { if os.Getenv("AWS_ACCESS_KEY_ID") == "" {
t.Skip("AWS_ACCESS_KEY_ID not set, skipping") t.Skip("AWS_ACCESS_KEY_ID not set, skipping")
} }
@ -277,7 +281,7 @@ func TestDiscoverEC2Hosts(t *testing.T) {
c := &Config{ c := &Config{
EC2Discovery: EC2Discovery{ EC2Discovery: EC2Discovery{
Region: "us-east-1", Region: os.Getenv("AWS_REGION"),
AccessKeyID: os.Getenv("AWS_ACCESS_KEY_ID"), AccessKeyID: os.Getenv("AWS_ACCESS_KEY_ID"),
SecretAccessKey: os.Getenv("AWS_SECRET_ACCESS_KEY"), SecretAccessKey: os.Getenv("AWS_SECRET_ACCESS_KEY"),
TagKey: "ConsulRole", TagKey: "ConsulRole",
@ -289,7 +293,6 @@ func TestDiscoverEC2Hosts(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
t.Log(servers)
if len(servers) != 3 { if len(servers) != 3 {
t.Fatalf("bad: %v", servers) t.Fatalf("bad: %v", servers)
} }

View File

@ -939,6 +939,36 @@ func TestDecodeConfig_invalidKeys(t *testing.T) {
} }
} }
func TestDecodeConfig_EC2Discovery(t *testing.T) {
input := `{"ec2_discovery": {
"region": "us-east-1",
"tag_key": "ConsulRole",
"tag_value": "Server",
"access_key_id": "asdf",
"secret_access_key": "qwerty"
}}`
config, err := DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
}
if config.EC2Discovery.Region != "us-east-1" {
t.Fatalf("bad: %#v", config)
}
if config.EC2Discovery.TagKey != "ConsulRole" {
t.Fatalf("bad: %#v", config)
}
if config.EC2Discovery.TagValue != "Server" {
t.Fatalf("bad: %#v", config)
}
if config.EC2Discovery.AccessKeyID != "asdf" {
t.Fatalf("bad: %#v", config)
}
if config.EC2Discovery.SecretAccessKey != "qwerty" {
t.Fatalf("bad: %#v", config)
}
}
func TestDecodeConfig_Performance(t *testing.T) { func TestDecodeConfig_Performance(t *testing.T) {
input := `{"performance": { "raft_multiplier": 3 }}` input := `{"performance": { "raft_multiplier": 3 }}`
config, err := DecodeConfig(bytes.NewReader([]byte(input))) config, err := DecodeConfig(bytes.NewReader([]byte(input)))
@ -1370,6 +1400,13 @@ func TestMergeConfig(t *testing.T) {
CheckUpdateIntervalRaw: "8m", CheckUpdateIntervalRaw: "8m",
RetryIntervalRaw: "10s", RetryIntervalRaw: "10s",
RetryIntervalWanRaw: "10s", RetryIntervalWanRaw: "10s",
EC2Discovery: EC2Discovery{
Region: "us-east-1",
TagKey: "Key1",
TagValue: "Value1",
AccessKeyID: "nope",
SecretAccessKey: "nope",
},
Telemetry: Telemetry{ Telemetry: Telemetry{
DisableHostname: false, DisableHostname: false,
StatsdAddr: "nope", StatsdAddr: "nope",
@ -1492,6 +1529,13 @@ func TestMergeConfig(t *testing.T) {
AtlasToken: "123456789", AtlasToken: "123456789",
AtlasACLToken: "abcdefgh", AtlasACLToken: "abcdefgh",
AtlasJoin: true, AtlasJoin: true,
EC2Discovery: EC2Discovery{
Region: "us-east-2",
TagKey: "Key2",
TagValue: "Value2",
AccessKeyID: "foo",
SecretAccessKey: "bar",
},
SessionTTLMinRaw: "1000s", SessionTTLMinRaw: "1000s",
SessionTTLMin: 1000 * time.Second, SessionTTLMin: 1000 * time.Second,
AdvertiseAddrs: AdvertiseAddrsConfig{ AdvertiseAddrs: AdvertiseAddrsConfig{