Add testing around EC2 discovery config
This commit is contained in:
parent
0499784b94
commit
d615141c16
|
@ -267,6 +267,10 @@ func TestRetryJoinWanFail(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") == "" {
|
||||
t.Skip("AWS_ACCESS_KEY_ID not set, skipping")
|
||||
}
|
||||
|
@ -277,7 +281,7 @@ func TestDiscoverEC2Hosts(t *testing.T) {
|
|||
|
||||
c := &Config{
|
||||
EC2Discovery: EC2Discovery{
|
||||
Region: "us-east-1",
|
||||
Region: os.Getenv("AWS_REGION"),
|
||||
AccessKeyID: os.Getenv("AWS_ACCESS_KEY_ID"),
|
||||
SecretAccessKey: os.Getenv("AWS_SECRET_ACCESS_KEY"),
|
||||
TagKey: "ConsulRole",
|
||||
|
@ -289,7 +293,6 @@ func TestDiscoverEC2Hosts(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(servers)
|
||||
if len(servers) != 3 {
|
||||
t.Fatalf("bad: %v", servers)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
input := `{"performance": { "raft_multiplier": 3 }}`
|
||||
config, err := DecodeConfig(bytes.NewReader([]byte(input)))
|
||||
|
@ -1370,6 +1400,13 @@ func TestMergeConfig(t *testing.T) {
|
|||
CheckUpdateIntervalRaw: "8m",
|
||||
RetryIntervalRaw: "10s",
|
||||
RetryIntervalWanRaw: "10s",
|
||||
EC2Discovery: EC2Discovery{
|
||||
Region: "us-east-1",
|
||||
TagKey: "Key1",
|
||||
TagValue: "Value1",
|
||||
AccessKeyID: "nope",
|
||||
SecretAccessKey: "nope",
|
||||
},
|
||||
Telemetry: Telemetry{
|
||||
DisableHostname: false,
|
||||
StatsdAddr: "nope",
|
||||
|
@ -1492,8 +1529,15 @@ func TestMergeConfig(t *testing.T) {
|
|||
AtlasToken: "123456789",
|
||||
AtlasACLToken: "abcdefgh",
|
||||
AtlasJoin: true,
|
||||
SessionTTLMinRaw: "1000s",
|
||||
SessionTTLMin: 1000 * time.Second,
|
||||
EC2Discovery: EC2Discovery{
|
||||
Region: "us-east-2",
|
||||
TagKey: "Key2",
|
||||
TagValue: "Value2",
|
||||
AccessKeyID: "foo",
|
||||
SecretAccessKey: "bar",
|
||||
},
|
||||
SessionTTLMinRaw: "1000s",
|
||||
SessionTTLMin: 1000 * time.Second,
|
||||
AdvertiseAddrs: AdvertiseAddrsConfig{
|
||||
SerfLan: &net.TCPAddr{},
|
||||
SerfLanRaw: "127.0.0.5:1231",
|
||||
|
|
Loading…
Reference in New Issue