2014-07-03 00:55:28 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2015-11-13 20:53:52 +01:00
|
|
|
"strings"
|
2014-07-03 00:55:28 +02:00
|
|
|
"testing"
|
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2016-04-27 14:08:59 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/apigateway"
|
2016-01-15 11:29:15 +01:00
|
|
|
"github.com/aws/aws-sdk-go/service/autoscaling"
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2015-06-08 23:06:32 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/elasticache"
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/elb"
|
2016-07-22 00:37:58 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/kinesis"
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/rds"
|
2015-11-12 00:37:56 +01:00
|
|
|
"github.com/aws/aws-sdk-go/service/redshift"
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/route53"
|
2014-07-03 00:55:28 +02:00
|
|
|
"github.com/hashicorp/terraform/flatmap"
|
2014-10-21 19:57:55 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2014-07-03 00:55:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Returns test configuration
|
2015-04-16 22:28:18 +02:00
|
|
|
func testConf() map[string]string {
|
2014-07-03 00:55:28 +02:00
|
|
|
return map[string]string{
|
|
|
|
"listener.#": "1",
|
|
|
|
"listener.0.lb_port": "80",
|
|
|
|
"listener.0.lb_protocol": "http",
|
|
|
|
"listener.0.instance_port": "8000",
|
|
|
|
"listener.0.instance_protocol": "http",
|
2014-07-03 01:57:57 +02:00
|
|
|
"availability_zones.#": "2",
|
|
|
|
"availability_zones.0": "us-east-1a",
|
|
|
|
"availability_zones.1": "us-east-1b",
|
2014-07-17 02:13:16 +02:00
|
|
|
"ingress.#": "1",
|
|
|
|
"ingress.0.protocol": "icmp",
|
|
|
|
"ingress.0.from_port": "1",
|
|
|
|
"ingress.0.to_port": "-1",
|
|
|
|
"ingress.0.cidr_blocks.#": "1",
|
|
|
|
"ingress.0.cidr_blocks.0": "0.0.0.0/0",
|
2014-08-08 20:42:32 +02:00
|
|
|
"ingress.0.security_groups.#": "2",
|
2014-07-17 02:13:16 +02:00
|
|
|
"ingress.0.security_groups.0": "sg-11111",
|
2014-08-08 20:42:32 +02:00
|
|
|
"ingress.0.security_groups.1": "foo/sg-22222",
|
2014-07-03 00:55:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestExpandIPPerms(t *testing.T) {
|
2015-04-09 15:38:16 +02:00
|
|
|
hash := schema.HashString
|
2014-10-21 19:57:55 +02:00
|
|
|
|
2014-08-20 19:54:43 +02:00
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "icmp",
|
|
|
|
"from_port": 1,
|
|
|
|
"to_port": -1,
|
|
|
|
"cidr_blocks": []interface{}{"0.0.0.0/0"},
|
2014-10-21 19:57:55 +02:00
|
|
|
"security_groups": schema.NewSet(hash, []interface{}{
|
2014-08-20 19:54:43 +02:00
|
|
|
"sg-11111",
|
|
|
|
"foo/sg-22222",
|
2014-10-21 19:57:55 +02:00
|
|
|
}),
|
2014-08-20 19:54:43 +02:00
|
|
|
},
|
2014-09-30 23:19:16 +02:00
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "icmp",
|
|
|
|
"from_port": 1,
|
|
|
|
"to_port": -1,
|
|
|
|
"self": true,
|
|
|
|
},
|
2014-07-25 00:50:18 +02:00
|
|
|
}
|
2015-04-16 22:18:01 +02:00
|
|
|
group := &ec2.SecurityGroup{
|
2015-08-17 20:27:16 +02:00
|
|
|
GroupId: aws.String("foo"),
|
|
|
|
VpcId: aws.String("bar"),
|
2015-03-18 14:47:59 +01:00
|
|
|
}
|
2015-05-05 05:56:54 +02:00
|
|
|
perms, err := expandIPPerms(group, expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error expanding perms: %v", err)
|
|
|
|
}
|
2014-08-20 19:54:43 +02:00
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
expected := []ec2.IpPermission{
|
|
|
|
ec2.IpPermission{
|
|
|
|
IpProtocol: aws.String("icmp"),
|
2015-07-28 22:29:46 +02:00
|
|
|
FromPort: aws.Int64(int64(1)),
|
|
|
|
ToPort: aws.Int64(int64(-1)),
|
2015-08-17 20:27:16 +02:00
|
|
|
IpRanges: []*ec2.IpRange{&ec2.IpRange{CidrIp: aws.String("0.0.0.0/0")}},
|
|
|
|
UserIdGroupPairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
|
|
|
UserId: aws.String("foo"),
|
|
|
|
GroupId: aws.String("sg-22222"),
|
2014-09-30 23:19:16 +02:00
|
|
|
},
|
2015-08-17 20:27:16 +02:00
|
|
|
&ec2.UserIdGroupPair{
|
2016-03-04 09:28:37 +01:00
|
|
|
GroupId: aws.String("sg-11111"),
|
2014-10-21 19:57:55 +02:00
|
|
|
},
|
2014-07-08 22:33:59 +02:00
|
|
|
},
|
2014-09-30 23:19:16 +02:00
|
|
|
},
|
2015-08-17 20:27:16 +02:00
|
|
|
ec2.IpPermission{
|
|
|
|
IpProtocol: aws.String("icmp"),
|
2015-07-28 22:29:46 +02:00
|
|
|
FromPort: aws.Int64(int64(1)),
|
|
|
|
ToPort: aws.Int64(int64(-1)),
|
2015-08-17 20:27:16 +02:00
|
|
|
UserIdGroupPairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
2016-03-04 09:28:37 +01:00
|
|
|
GroupId: aws.String("foo"),
|
2014-09-30 23:19:16 +02:00
|
|
|
},
|
2014-08-08 20:42:32 +02:00
|
|
|
},
|
2014-07-29 16:02:49 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-03-10 22:33:15 +01:00
|
|
|
exp := expected[0]
|
|
|
|
perm := perms[0]
|
|
|
|
|
|
|
|
if *exp.FromPort != *perm.FromPort {
|
2014-07-29 16:02:49 +02:00
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-03-10 22:33:15 +01:00
|
|
|
*perm.FromPort,
|
|
|
|
*exp.FromPort)
|
2014-07-29 16:02:49 +02:00
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if *exp.IpRanges[0].CidrIp != *perm.IpRanges[0].CidrIp {
|
2015-03-10 22:33:15 +01:00
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-08-17 20:27:16 +02:00
|
|
|
*perm.IpRanges[0].CidrIp,
|
|
|
|
*exp.IpRanges[0].CidrIp)
|
2014-07-17 02:13:16 +02:00
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if *exp.UserIdGroupPairs[0].UserId != *perm.UserIdGroupPairs[0].UserId {
|
2015-03-10 22:33:15 +01:00
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-08-17 20:27:16 +02:00
|
|
|
*perm.UserIdGroupPairs[0].UserId,
|
|
|
|
*exp.UserIdGroupPairs[0].UserId)
|
2014-07-17 02:13:16 +02:00
|
|
|
}
|
2015-03-10 22:33:15 +01:00
|
|
|
|
2016-03-04 09:28:37 +01:00
|
|
|
if *exp.UserIdGroupPairs[0].GroupId != *perm.UserIdGroupPairs[0].GroupId {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
*perm.UserIdGroupPairs[0].GroupId,
|
|
|
|
*exp.UserIdGroupPairs[0].GroupId)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *exp.UserIdGroupPairs[1].GroupId != *perm.UserIdGroupPairs[1].GroupId {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
*perm.UserIdGroupPairs[1].GroupId,
|
|
|
|
*exp.UserIdGroupPairs[1].GroupId)
|
|
|
|
}
|
|
|
|
|
|
|
|
exp = expected[1]
|
|
|
|
perm = perms[1]
|
|
|
|
|
|
|
|
if *exp.UserIdGroupPairs[0].GroupId != *perm.UserIdGroupPairs[0].GroupId {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
*perm.UserIdGroupPairs[0].GroupId,
|
|
|
|
*exp.UserIdGroupPairs[0].GroupId)
|
|
|
|
}
|
2014-07-17 02:13:16 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 05:56:54 +02:00
|
|
|
func TestExpandIPPerms_NegOneProtocol(t *testing.T) {
|
2015-05-08 00:18:47 +02:00
|
|
|
hash := schema.HashString
|
2015-05-05 05:56:54 +02:00
|
|
|
|
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "-1",
|
|
|
|
"from_port": 0,
|
|
|
|
"to_port": 0,
|
|
|
|
"cidr_blocks": []interface{}{"0.0.0.0/0"},
|
|
|
|
"security_groups": schema.NewSet(hash, []interface{}{
|
|
|
|
"sg-11111",
|
|
|
|
"foo/sg-22222",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
group := &ec2.SecurityGroup{
|
2015-08-17 20:27:16 +02:00
|
|
|
GroupId: aws.String("foo"),
|
|
|
|
VpcId: aws.String("bar"),
|
2015-05-05 05:56:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
perms, err := expandIPPerms(group, expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error expanding perms: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
expected := []ec2.IpPermission{
|
|
|
|
ec2.IpPermission{
|
|
|
|
IpProtocol: aws.String("-1"),
|
2015-07-28 22:29:46 +02:00
|
|
|
FromPort: aws.Int64(int64(0)),
|
|
|
|
ToPort: aws.Int64(int64(0)),
|
2015-08-17 20:27:16 +02:00
|
|
|
IpRanges: []*ec2.IpRange{&ec2.IpRange{CidrIp: aws.String("0.0.0.0/0")}},
|
|
|
|
UserIdGroupPairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
|
|
|
UserId: aws.String("foo"),
|
|
|
|
GroupId: aws.String("sg-22222"),
|
2015-05-05 05:56:54 +02:00
|
|
|
},
|
2015-08-17 20:27:16 +02:00
|
|
|
&ec2.UserIdGroupPair{
|
2016-03-04 09:28:37 +01:00
|
|
|
GroupId: aws.String("sg-11111"),
|
2015-05-05 05:56:54 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exp := expected[0]
|
|
|
|
perm := perms[0]
|
|
|
|
|
|
|
|
if *exp.FromPort != *perm.FromPort {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
*perm.FromPort,
|
|
|
|
*exp.FromPort)
|
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if *exp.IpRanges[0].CidrIp != *perm.IpRanges[0].CidrIp {
|
2015-05-05 05:56:54 +02:00
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-08-17 20:27:16 +02:00
|
|
|
*perm.IpRanges[0].CidrIp,
|
|
|
|
*exp.IpRanges[0].CidrIp)
|
2015-05-05 05:56:54 +02:00
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if *exp.UserIdGroupPairs[0].UserId != *perm.UserIdGroupPairs[0].UserId {
|
2015-05-05 05:56:54 +02:00
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-08-17 20:27:16 +02:00
|
|
|
*perm.UserIdGroupPairs[0].UserId,
|
|
|
|
*exp.UserIdGroupPairs[0].UserId)
|
2015-05-05 05:56:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now test the error case. This *should* error when either from_port
|
2015-09-11 20:56:20 +02:00
|
|
|
// or to_port is not zero, but protocol is "-1".
|
2015-05-05 05:56:54 +02:00
|
|
|
errorCase := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "-1",
|
|
|
|
"from_port": 0,
|
|
|
|
"to_port": 65535,
|
|
|
|
"cidr_blocks": []interface{}{"0.0.0.0/0"},
|
|
|
|
"security_groups": schema.NewSet(hash, []interface{}{
|
|
|
|
"sg-11111",
|
|
|
|
"foo/sg-22222",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
securityGroups := &ec2.SecurityGroup{
|
2015-08-17 20:27:16 +02:00
|
|
|
GroupId: aws.String("foo"),
|
|
|
|
VpcId: aws.String("bar"),
|
2015-05-05 05:56:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_, expandErr := expandIPPerms(securityGroups, errorCase)
|
|
|
|
if expandErr == nil {
|
|
|
|
t.Fatal("expandIPPerms should have errored!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:28:18 +02:00
|
|
|
func TestExpandIPPerms_nonVPC(t *testing.T) {
|
2015-04-09 15:38:16 +02:00
|
|
|
hash := schema.HashString
|
2015-03-18 14:47:59 +01:00
|
|
|
|
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "icmp",
|
|
|
|
"from_port": 1,
|
|
|
|
"to_port": -1,
|
|
|
|
"cidr_blocks": []interface{}{"0.0.0.0/0"},
|
|
|
|
"security_groups": schema.NewSet(hash, []interface{}{
|
|
|
|
"sg-11111",
|
|
|
|
"foo/sg-22222",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "icmp",
|
|
|
|
"from_port": 1,
|
|
|
|
"to_port": -1,
|
|
|
|
"self": true,
|
|
|
|
},
|
|
|
|
}
|
2015-04-16 22:18:01 +02:00
|
|
|
group := &ec2.SecurityGroup{
|
2015-03-18 14:47:59 +01:00
|
|
|
GroupName: aws.String("foo"),
|
|
|
|
}
|
2015-05-05 05:56:54 +02:00
|
|
|
perms, err := expandIPPerms(group, expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error expanding perms: %v", err)
|
|
|
|
}
|
2015-03-18 14:47:59 +01:00
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
expected := []ec2.IpPermission{
|
|
|
|
ec2.IpPermission{
|
|
|
|
IpProtocol: aws.String("icmp"),
|
2015-07-28 22:29:46 +02:00
|
|
|
FromPort: aws.Int64(int64(1)),
|
|
|
|
ToPort: aws.Int64(int64(-1)),
|
2015-08-17 20:27:16 +02:00
|
|
|
IpRanges: []*ec2.IpRange{&ec2.IpRange{CidrIp: aws.String("0.0.0.0/0")}},
|
|
|
|
UserIdGroupPairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
2015-03-18 14:47:59 +01:00
|
|
|
GroupName: aws.String("sg-22222"),
|
|
|
|
},
|
2015-08-17 20:27:16 +02:00
|
|
|
&ec2.UserIdGroupPair{
|
2016-03-04 09:28:37 +01:00
|
|
|
GroupName: aws.String("sg-11111"),
|
2015-03-18 14:47:59 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-08-17 20:27:16 +02:00
|
|
|
ec2.IpPermission{
|
|
|
|
IpProtocol: aws.String("icmp"),
|
2015-07-28 22:29:46 +02:00
|
|
|
FromPort: aws.Int64(int64(1)),
|
|
|
|
ToPort: aws.Int64(int64(-1)),
|
2015-08-17 20:27:16 +02:00
|
|
|
UserIdGroupPairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
2015-03-18 14:47:59 +01:00
|
|
|
GroupName: aws.String("foo"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exp := expected[0]
|
|
|
|
perm := perms[0]
|
|
|
|
|
|
|
|
if *exp.FromPort != *perm.FromPort {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
*perm.FromPort,
|
|
|
|
*exp.FromPort)
|
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if *exp.IpRanges[0].CidrIp != *perm.IpRanges[0].CidrIp {
|
2015-03-18 14:47:59 +01:00
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-08-17 20:27:16 +02:00
|
|
|
*perm.IpRanges[0].CidrIp,
|
|
|
|
*exp.IpRanges[0].CidrIp)
|
2015-03-18 14:47:59 +01:00
|
|
|
}
|
2016-03-04 09:28:37 +01:00
|
|
|
|
|
|
|
if *exp.UserIdGroupPairs[0].GroupName != *perm.UserIdGroupPairs[0].GroupName {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
*perm.UserIdGroupPairs[0].GroupName,
|
|
|
|
*exp.UserIdGroupPairs[0].GroupName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *exp.UserIdGroupPairs[1].GroupName != *perm.UserIdGroupPairs[1].GroupName {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
*perm.UserIdGroupPairs[1].GroupName,
|
|
|
|
*exp.UserIdGroupPairs[1].GroupName)
|
|
|
|
}
|
|
|
|
|
|
|
|
exp = expected[1]
|
|
|
|
perm = perms[1]
|
|
|
|
|
|
|
|
if *exp.UserIdGroupPairs[0].GroupName != *perm.UserIdGroupPairs[0].GroupName {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
*perm.UserIdGroupPairs[0].GroupName,
|
|
|
|
*exp.UserIdGroupPairs[0].GroupName)
|
|
|
|
}
|
2015-03-18 14:47:59 +01:00
|
|
|
}
|
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestExpandListeners(t *testing.T) {
|
2014-10-10 19:26:48 +02:00
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
2014-10-10 23:50:35 +02:00
|
|
|
"instance_port": 8000,
|
|
|
|
"lb_port": 80,
|
2014-10-10 19:26:48 +02:00
|
|
|
"instance_protocol": "http",
|
2014-10-10 23:50:35 +02:00
|
|
|
"lb_protocol": "http",
|
2014-10-10 19:26:48 +02:00
|
|
|
},
|
2015-11-13 20:53:52 +01:00
|
|
|
map[string]interface{}{
|
|
|
|
"instance_port": 8000,
|
|
|
|
"lb_port": 80,
|
|
|
|
"instance_protocol": "https",
|
|
|
|
"lb_protocol": "https",
|
|
|
|
"ssl_certificate_id": "something",
|
|
|
|
},
|
2014-10-10 19:26:48 +02:00
|
|
|
}
|
2015-04-16 22:28:18 +02:00
|
|
|
listeners, err := expandListeners(expanded)
|
2014-07-25 00:50:18 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:18:01 +02:00
|
|
|
expected := &elb.Listener{
|
2015-07-28 22:29:46 +02:00
|
|
|
InstancePort: aws.Int64(int64(8000)),
|
|
|
|
LoadBalancerPort: aws.Int64(int64(80)),
|
2015-03-02 16:44:06 +01:00
|
|
|
InstanceProtocol: aws.String("http"),
|
|
|
|
Protocol: aws.String("http"),
|
2014-07-03 00:55:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(listeners[0], expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
listeners[0],
|
|
|
|
expected)
|
|
|
|
}
|
2015-11-12 18:10:52 +01:00
|
|
|
}
|
2014-07-03 00:55:28 +02:00
|
|
|
|
2015-11-12 18:10:52 +01:00
|
|
|
// this test should produce an error from expandlisteners on an invalid
|
|
|
|
// combination
|
|
|
|
func TestExpandListeners_invalid(t *testing.T) {
|
2015-11-13 20:53:52 +01:00
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"instance_port": 8000,
|
|
|
|
"lb_port": 80,
|
|
|
|
"instance_protocol": "http",
|
|
|
|
"lb_protocol": "http",
|
|
|
|
"ssl_certificate_id": "something",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, err := expandListeners(expanded)
|
|
|
|
if err != nil {
|
|
|
|
// Check the error we got
|
|
|
|
if !strings.Contains(err.Error(), "ssl_certificate_id may be set only when protocol") {
|
|
|
|
t.Fatalf("Got error in TestExpandListeners_invalid, but not what we expected: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected TestExpandListeners_invalid to fail, but passed")
|
|
|
|
}
|
2014-07-03 00:55:28 +02:00
|
|
|
}
|
2014-07-03 01:57:57 +02:00
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestFlattenHealthCheck(t *testing.T) {
|
2014-07-30 16:15:22 +02:00
|
|
|
cases := []struct {
|
2015-04-16 22:18:01 +02:00
|
|
|
Input *elb.HealthCheck
|
2014-07-30 16:15:22 +02:00
|
|
|
Output []map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
2015-04-16 22:18:01 +02:00
|
|
|
Input: &elb.HealthCheck{
|
2015-07-28 22:29:46 +02:00
|
|
|
UnhealthyThreshold: aws.Int64(int64(10)),
|
|
|
|
HealthyThreshold: aws.Int64(int64(10)),
|
2015-03-02 16:44:06 +01:00
|
|
|
Target: aws.String("HTTP:80/"),
|
2015-07-28 22:29:46 +02:00
|
|
|
Timeout: aws.Int64(int64(30)),
|
|
|
|
Interval: aws.Int64(int64(30)),
|
2014-07-30 16:15:22 +02:00
|
|
|
},
|
|
|
|
Output: []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
2015-04-16 22:18:01 +02:00
|
|
|
"unhealthy_threshold": int64(10),
|
|
|
|
"healthy_threshold": int64(10),
|
2014-07-30 16:15:22 +02:00
|
|
|
"target": "HTTP:80/",
|
2015-04-16 22:18:01 +02:00
|
|
|
"timeout": int64(30),
|
|
|
|
"interval": int64(30),
|
2014-07-30 16:15:22 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2015-04-16 22:28:18 +02:00
|
|
|
output := flattenHealthCheck(tc.Input)
|
2014-07-30 16:15:22 +02:00
|
|
|
if !reflect.DeepEqual(output, tc.Output) {
|
|
|
|
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:28:18 +02:00
|
|
|
func TestExpandStringList(t *testing.T) {
|
|
|
|
expanded := flatmap.Expand(testConf(), "availability_zones").([]interface{})
|
2014-07-03 01:57:57 +02:00
|
|
|
stringList := expandStringList(expanded)
|
2015-04-16 22:28:18 +02:00
|
|
|
expected := []*string{
|
|
|
|
aws.String("us-east-1a"),
|
|
|
|
aws.String("us-east-1b"),
|
2014-07-03 01:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(stringList, expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
stringList,
|
|
|
|
expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-10-22 23:22:30 +02:00
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestExpandParameters(t *testing.T) {
|
2014-10-22 23:22:30 +02:00
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "character_set_client",
|
|
|
|
"value": "utf8",
|
|
|
|
"apply_method": "immediate",
|
|
|
|
},
|
|
|
|
}
|
2015-04-16 22:28:18 +02:00
|
|
|
parameters, err := expandParameters(expanded)
|
2014-10-22 23:22:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:18:01 +02:00
|
|
|
expected := &rds.Parameter{
|
2015-02-26 16:33:33 +01:00
|
|
|
ParameterName: aws.String("character_set_client"),
|
|
|
|
ParameterValue: aws.String("utf8"),
|
|
|
|
ApplyMethod: aws.String("immediate"),
|
2014-10-22 23:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(parameters[0], expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
parameters[0],
|
|
|
|
expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:05:57 +02:00
|
|
|
func TestExpandRedshiftParameters(t *testing.T) {
|
2015-11-12 00:37:56 +01:00
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "character_set_client",
|
|
|
|
"value": "utf8",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
parameters, err := expandRedshiftParameters(expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &redshift.Parameter{
|
|
|
|
ParameterName: aws.String("character_set_client"),
|
|
|
|
ParameterValue: aws.String("utf8"),
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(parameters[0], expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
parameters[0],
|
|
|
|
expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:05:57 +02:00
|
|
|
func TestExpandElasticacheParameters(t *testing.T) {
|
2015-06-08 23:06:32 +02:00
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
2015-11-12 17:45:49 +01:00
|
|
|
"name": "activerehashing",
|
|
|
|
"value": "yes",
|
2015-06-08 23:06:32 +02:00
|
|
|
"apply_method": "immediate",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
parameters, err := expandElastiCacheParameters(expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
2015-11-12 17:45:49 +01:00
|
|
|
expected := &elasticache.ParameterNameValue{
|
2015-06-08 23:06:32 +02:00
|
|
|
ParameterName: aws.String("activerehashing"),
|
|
|
|
ParameterValue: aws.String("yes"),
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(parameters[0], expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
parameters[0],
|
|
|
|
expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-12 00:53:45 +01:00
|
|
|
func TestExpandStepAdjustments(t *testing.T) {
|
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"metric_interval_lower_bound": "1.0",
|
|
|
|
"metric_interval_upper_bound": "2.0",
|
|
|
|
"scaling_adjustment": 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
parameters, err := expandStepAdjustments(expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &autoscaling.StepAdjustment{
|
|
|
|
MetricIntervalLowerBound: aws.Float64(1.0),
|
|
|
|
MetricIntervalUpperBound: aws.Float64(2.0),
|
|
|
|
ScalingAdjustment: aws.Int64(int64(1)),
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(parameters[0], expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
parameters[0],
|
|
|
|
expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestFlattenParameters(t *testing.T) {
|
2014-10-22 23:22:30 +02:00
|
|
|
cases := []struct {
|
2015-04-16 22:18:01 +02:00
|
|
|
Input []*rds.Parameter
|
2014-10-22 23:22:30 +02:00
|
|
|
Output []map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
2015-04-16 22:18:01 +02:00
|
|
|
Input: []*rds.Parameter{
|
|
|
|
&rds.Parameter{
|
2015-02-26 16:33:33 +01:00
|
|
|
ParameterName: aws.String("character_set_client"),
|
|
|
|
ParameterValue: aws.String("utf8"),
|
2014-10-22 23:22:30 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Output: []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
2015-02-20 19:22:26 +01:00
|
|
|
"name": "character_set_client",
|
|
|
|
"value": "utf8",
|
2014-10-22 23:22:30 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2015-04-16 22:28:18 +02:00
|
|
|
output := flattenParameters(tc.Input)
|
2014-10-22 23:22:30 +02:00
|
|
|
if !reflect.DeepEqual(output, tc.Output) {
|
|
|
|
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-02 17:00:45 +01:00
|
|
|
|
2016-07-29 22:05:57 +02:00
|
|
|
func TestFlattenRedshiftParameters(t *testing.T) {
|
2015-11-12 00:37:56 +01:00
|
|
|
cases := []struct {
|
|
|
|
Input []*redshift.Parameter
|
|
|
|
Output []map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Input: []*redshift.Parameter{
|
|
|
|
&redshift.Parameter{
|
|
|
|
ParameterName: aws.String("character_set_client"),
|
|
|
|
ParameterValue: aws.String("utf8"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Output: []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "character_set_client",
|
|
|
|
"value": "utf8",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
output := flattenRedshiftParameters(tc.Input)
|
|
|
|
if !reflect.DeepEqual(output, tc.Output) {
|
|
|
|
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:05:57 +02:00
|
|
|
func TestFlattenElasticacheParameters(t *testing.T) {
|
2015-06-08 23:06:32 +02:00
|
|
|
cases := []struct {
|
|
|
|
Input []*elasticache.Parameter
|
|
|
|
Output []map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Input: []*elasticache.Parameter{
|
|
|
|
&elasticache.Parameter{
|
|
|
|
ParameterName: aws.String("activerehashing"),
|
|
|
|
ParameterValue: aws.String("yes"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Output: []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "activerehashing",
|
|
|
|
"value": "yes",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
output := flattenElastiCacheParameters(tc.Input)
|
|
|
|
if !reflect.DeepEqual(output, tc.Output) {
|
|
|
|
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestExpandInstanceString(t *testing.T) {
|
2015-03-02 17:00:45 +01:00
|
|
|
|
2015-04-16 22:18:01 +02:00
|
|
|
expected := []*elb.Instance{
|
2015-08-17 20:27:16 +02:00
|
|
|
&elb.Instance{InstanceId: aws.String("test-one")},
|
|
|
|
&elb.Instance{InstanceId: aws.String("test-two")},
|
2015-03-02 17:00:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ids := []interface{}{
|
|
|
|
"test-one",
|
|
|
|
"test-two",
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:28:18 +02:00
|
|
|
expanded := expandInstanceString(ids)
|
2015-03-02 17:00:45 +01:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(expanded, expected) {
|
|
|
|
t.Fatalf("Expand Instance String output did not match.\nGot:\n%#v\n\nexpected:\n%#v", expanded, expected)
|
|
|
|
}
|
|
|
|
}
|
2015-03-17 13:42:05 +01:00
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestFlattenNetworkInterfacesPrivateIPAddresses(t *testing.T) {
|
2015-08-17 20:27:16 +02:00
|
|
|
expanded := []*ec2.NetworkInterfacePrivateIpAddress{
|
|
|
|
&ec2.NetworkInterfacePrivateIpAddress{PrivateIpAddress: aws.String("192.168.0.1")},
|
|
|
|
&ec2.NetworkInterfacePrivateIpAddress{PrivateIpAddress: aws.String("192.168.0.2")},
|
2015-03-17 13:42:05 +01:00
|
|
|
}
|
|
|
|
|
2015-09-11 20:56:20 +02:00
|
|
|
result := flattenNetworkInterfacesPrivateIPAddresses(expanded)
|
2015-03-17 13:42:05 +01:00
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result was nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(result) != 2 {
|
|
|
|
t.Fatalf("expected result had %d elements, but got %d", 2, len(result))
|
|
|
|
}
|
|
|
|
|
|
|
|
if result[0] != "192.168.0.1" {
|
|
|
|
t.Fatalf("expected ip to be 192.168.0.1, but was %s", result[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
if result[1] != "192.168.0.2" {
|
|
|
|
t.Fatalf("expected ip to be 192.168.0.2, but was %s", result[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestFlattenGroupIdentifiers(t *testing.T) {
|
2015-04-16 22:18:01 +02:00
|
|
|
expanded := []*ec2.GroupIdentifier{
|
2015-08-17 20:27:16 +02:00
|
|
|
&ec2.GroupIdentifier{GroupId: aws.String("sg-001")},
|
|
|
|
&ec2.GroupIdentifier{GroupId: aws.String("sg-002")},
|
2015-03-17 13:42:05 +01:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:28:18 +02:00
|
|
|
result := flattenGroupIdentifiers(expanded)
|
2015-03-17 13:42:05 +01:00
|
|
|
|
|
|
|
if len(result) != 2 {
|
|
|
|
t.Fatalf("expected result had %d elements, but got %d", 2, len(result))
|
|
|
|
}
|
|
|
|
|
|
|
|
if result[0] != "sg-001" {
|
|
|
|
t.Fatalf("expected id to be sg-001, but was %s", result[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
if result[1] != "sg-002" {
|
|
|
|
t.Fatalf("expected id to be sg-002, but was %s", result[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestExpandPrivateIPAddresses(t *testing.T) {
|
2015-03-17 14:00:36 +01:00
|
|
|
|
2015-03-17 13:42:05 +01:00
|
|
|
ip1 := "192.168.0.1"
|
|
|
|
ip2 := "192.168.0.2"
|
2015-03-17 14:00:36 +01:00
|
|
|
flattened := []interface{}{
|
2015-03-17 13:42:05 +01:00
|
|
|
ip1,
|
|
|
|
ip2,
|
|
|
|
}
|
|
|
|
|
2015-09-11 20:56:20 +02:00
|
|
|
result := expandPrivateIPAddresses(flattened)
|
2015-03-17 13:42:05 +01:00
|
|
|
|
|
|
|
if len(result) != 2 {
|
|
|
|
t.Fatalf("expected result had %d elements, but got %d", 2, len(result))
|
|
|
|
}
|
2015-03-17 14:00:36 +01:00
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if *result[0].PrivateIpAddress != "192.168.0.1" || !*result[0].Primary {
|
|
|
|
t.Fatalf("expected ip to be 192.168.0.1 and Primary, but got %v, %t", *result[0].PrivateIpAddress, *result[0].Primary)
|
2015-03-17 13:42:05 +01:00
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if *result[1].PrivateIpAddress != "192.168.0.2" || *result[1].Primary {
|
|
|
|
t.Fatalf("expected ip to be 192.168.0.2 and not Primary, but got %v, %t", *result[1].PrivateIpAddress, *result[1].Primary)
|
2015-03-17 13:42:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 17:36:22 +01:00
|
|
|
func TestFlattenAttachment(t *testing.T) {
|
2015-03-17 13:42:05 +01:00
|
|
|
expanded := &ec2.NetworkInterfaceAttachment{
|
2015-08-17 20:27:16 +02:00
|
|
|
InstanceId: aws.String("i-00001"),
|
2015-07-28 22:29:46 +02:00
|
|
|
DeviceIndex: aws.Int64(int64(1)),
|
2015-08-17 20:27:16 +02:00
|
|
|
AttachmentId: aws.String("at-002"),
|
2015-03-17 13:42:05 +01:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:28:18 +02:00
|
|
|
result := flattenAttachment(expanded)
|
2015-03-17 13:42:05 +01:00
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("expected result to have value, but got nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if result["instance"] != "i-00001" {
|
|
|
|
t.Fatalf("expected instance to be i-00001, but got %s", result["instance"])
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:18:01 +02:00
|
|
|
if result["device_index"] != int64(1) {
|
2015-03-17 13:42:05 +01:00
|
|
|
t.Fatalf("expected device_index to be 1, but got %d", result["device_index"])
|
|
|
|
}
|
|
|
|
|
|
|
|
if result["attachment_id"] != "at-002" {
|
|
|
|
t.Fatalf("expected attachment_id to be at-002, but got %s", result["attachment_id"])
|
|
|
|
}
|
2015-03-17 14:00:36 +01:00
|
|
|
}
|
2015-04-16 22:18:01 +02:00
|
|
|
|
2016-05-24 15:52:38 +02:00
|
|
|
func TestFlattenAttachmentWhenNoInstanceId(t *testing.T) {
|
|
|
|
expanded := &ec2.NetworkInterfaceAttachment{
|
|
|
|
DeviceIndex: aws.Int64(int64(1)),
|
|
|
|
AttachmentId: aws.String("at-002"),
|
|
|
|
}
|
|
|
|
|
|
|
|
result := flattenAttachment(expanded)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("expected result to have value, but got nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if result["instance"] != nil {
|
|
|
|
t.Fatalf("expected instance to be nil, but got %s", result["instance"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:05:57 +02:00
|
|
|
func TestFlattenStepAdjustments(t *testing.T) {
|
2015-12-12 00:53:45 +01:00
|
|
|
expanded := []*autoscaling.StepAdjustment{
|
|
|
|
&autoscaling.StepAdjustment{
|
|
|
|
MetricIntervalLowerBound: aws.Float64(1.0),
|
|
|
|
MetricIntervalUpperBound: aws.Float64(2.0),
|
|
|
|
ScalingAdjustment: aws.Int64(int64(1)),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
result := flattenStepAdjustments(expanded)[0]
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("expected result to have value, but got nil")
|
|
|
|
}
|
|
|
|
if result["metric_interval_lower_bound"] != float64(1.0) {
|
|
|
|
t.Fatalf("expected metric_interval_lower_bound to be 1.0, but got %d", result["metric_interval_lower_bound"])
|
|
|
|
}
|
|
|
|
if result["metric_interval_upper_bound"] != float64(2.0) {
|
|
|
|
t.Fatalf("expected metric_interval_upper_bound to be 1.0, but got %d", result["metric_interval_upper_bound"])
|
|
|
|
}
|
|
|
|
if result["scaling_adjustment"] != int64(1) {
|
|
|
|
t.Fatalf("expected scaling_adjustment to be 1, but got %d", result["scaling_adjustment"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:18:01 +02:00
|
|
|
func TestFlattenResourceRecords(t *testing.T) {
|
|
|
|
expanded := []*route53.ResourceRecord{
|
|
|
|
&route53.ResourceRecord{
|
|
|
|
Value: aws.String("127.0.0.1"),
|
|
|
|
},
|
|
|
|
&route53.ResourceRecord{
|
|
|
|
Value: aws.String("127.0.0.3"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
result := flattenResourceRecords(expanded)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("expected result to have value, but got nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(result) != 2 {
|
|
|
|
t.Fatal("expected result to have value, but got nil")
|
|
|
|
}
|
|
|
|
}
|
2016-01-15 11:29:15 +01:00
|
|
|
|
|
|
|
func TestFlattenAsgEnabledMetrics(t *testing.T) {
|
|
|
|
expanded := []*autoscaling.EnabledMetric{
|
|
|
|
&autoscaling.EnabledMetric{Granularity: aws.String("1Minute"), Metric: aws.String("GroupTotalInstances")},
|
|
|
|
&autoscaling.EnabledMetric{Granularity: aws.String("1Minute"), Metric: aws.String("GroupMaxSize")},
|
|
|
|
}
|
|
|
|
|
|
|
|
result := flattenAsgEnabledMetrics(expanded)
|
|
|
|
|
|
|
|
if len(result) != 2 {
|
|
|
|
t.Fatalf("expected result had %d elements, but got %d", 2, len(result))
|
|
|
|
}
|
|
|
|
|
|
|
|
if result[0] != "GroupTotalInstances" {
|
|
|
|
t.Fatalf("expected id to be GroupTotalInstances, but was %s", result[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
if result[1] != "GroupMaxSize" {
|
|
|
|
t.Fatalf("expected id to be GroupMaxSize, but was %s", result[1])
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 22:00:30 +01:00
|
|
|
|
2016-07-22 00:37:58 +02:00
|
|
|
func TestFlattenKinesisShardLevelMetrics(t *testing.T) {
|
|
|
|
expanded := []*kinesis.EnhancedMetrics{
|
|
|
|
&kinesis.EnhancedMetrics{
|
|
|
|
ShardLevelMetrics: []*string{
|
|
|
|
aws.String("IncomingBytes"),
|
|
|
|
aws.String("IncomingRecords"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
result := flattenKinesisShardLevelMetrics(expanded)
|
|
|
|
if len(result) != 2 {
|
|
|
|
t.Fatalf("expected result had %d elements, but got %d", 2, len(result))
|
|
|
|
}
|
|
|
|
if result[0] != "IncomingBytes" {
|
|
|
|
t.Fatalf("expected element 0 to be IncomingBytes, but was %s", result[0])
|
|
|
|
}
|
|
|
|
if result[1] != "IncomingRecords" {
|
|
|
|
t.Fatalf("expected element 0 to be IncomingRecords, but was %s", result[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 22:00:30 +01:00
|
|
|
func TestFlattenSecurityGroups(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
ownerId *string
|
|
|
|
pairs []*ec2.UserIdGroupPair
|
|
|
|
expected []*ec2.GroupIdentifier
|
|
|
|
}{
|
|
|
|
// simple, no user id included (we ignore it mostly)
|
|
|
|
{
|
|
|
|
ownerId: aws.String("user1234"),
|
|
|
|
pairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
|
|
|
GroupId: aws.String("sg-12345"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: []*ec2.GroupIdentifier{
|
|
|
|
&ec2.GroupIdentifier{
|
|
|
|
GroupId: aws.String("sg-12345"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// include the owner id, but keep it consitent with the same account. Tests
|
|
|
|
// EC2 classic situation
|
|
|
|
{
|
|
|
|
ownerId: aws.String("user1234"),
|
|
|
|
pairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
|
|
|
GroupId: aws.String("sg-12345"),
|
|
|
|
UserId: aws.String("user1234"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: []*ec2.GroupIdentifier{
|
|
|
|
&ec2.GroupIdentifier{
|
|
|
|
GroupId: aws.String("sg-12345"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// include the owner id, but from a different account. This is reflects
|
2016-09-12 08:14:24 +02:00
|
|
|
// EC2 Classic when referring to groups by name
|
2016-03-09 22:00:30 +01:00
|
|
|
{
|
|
|
|
ownerId: aws.String("user1234"),
|
|
|
|
pairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
|
|
|
GroupId: aws.String("sg-12345"),
|
|
|
|
GroupName: aws.String("somegroup"), // GroupName is only included in Classic
|
|
|
|
UserId: aws.String("user4321"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: []*ec2.GroupIdentifier{
|
|
|
|
&ec2.GroupIdentifier{
|
|
|
|
GroupId: aws.String("sg-12345"),
|
|
|
|
GroupName: aws.String("user4321/somegroup"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// include the owner id, but from a different account. This reflects in
|
2016-09-12 08:14:24 +02:00
|
|
|
// EC2 VPC when referring to groups by id
|
2016-03-09 22:00:30 +01:00
|
|
|
{
|
|
|
|
ownerId: aws.String("user1234"),
|
|
|
|
pairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
|
|
|
GroupId: aws.String("sg-12345"),
|
|
|
|
UserId: aws.String("user4321"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: []*ec2.GroupIdentifier{
|
|
|
|
&ec2.GroupIdentifier{
|
|
|
|
GroupId: aws.String("user4321/sg-12345"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
out := flattenSecurityGroups(c.pairs, c.ownerId)
|
|
|
|
if !reflect.DeepEqual(out, c.expected) {
|
|
|
|
t.Fatalf("Error matching output and expected: %#v vs %#v", out, c.expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-27 14:08:59 +02:00
|
|
|
|
|
|
|
func TestFlattenApiGatewayThrottleSettings(t *testing.T) {
|
|
|
|
expectedBurstLimit := int64(140)
|
|
|
|
expectedRateLimit := 120.0
|
|
|
|
|
|
|
|
ts := &apigateway.ThrottleSettings{
|
|
|
|
BurstLimit: aws.Int64(expectedBurstLimit),
|
|
|
|
RateLimit: aws.Float64(expectedRateLimit),
|
|
|
|
}
|
|
|
|
result := flattenApiGatewayThrottleSettings(ts)
|
|
|
|
|
|
|
|
if len(result) != 1 {
|
|
|
|
t.Fatalf("Expected map to have exactly 1 element, got %d", len(result))
|
|
|
|
}
|
|
|
|
|
|
|
|
burstLimit, ok := result[0]["burst_limit"]
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("Expected 'burst_limit' key in the map")
|
|
|
|
}
|
|
|
|
burstLimitInt, ok := burstLimit.(int64)
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("Expected 'burst_limit' to be int")
|
|
|
|
}
|
|
|
|
if burstLimitInt != expectedBurstLimit {
|
|
|
|
t.Fatalf("Expected 'burst_limit' to equal %d, got %d", expectedBurstLimit, burstLimitInt)
|
|
|
|
}
|
|
|
|
|
|
|
|
rateLimit, ok := result[0]["rate_limit"]
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("Expected 'rate_limit' key in the map")
|
|
|
|
}
|
|
|
|
rateLimitFloat, ok := rateLimit.(float64)
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("Expected 'rate_limit' to be float64")
|
|
|
|
}
|
|
|
|
if rateLimitFloat != expectedRateLimit {
|
|
|
|
t.Fatalf("Expected 'rate_limit' to equal %f, got %f", expectedRateLimit, rateLimitFloat)
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 12:21:47 +02:00
|
|
|
|
|
|
|
func TestFlattenApiGatewayStageKeys(t *testing.T) {
|
2016-07-11 23:10:13 +02:00
|
|
|
cases := []struct {
|
|
|
|
Input []*string
|
|
|
|
Output []map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Input: []*string{
|
|
|
|
aws.String("a1b2c3d4e5/dev"),
|
|
|
|
aws.String("e5d4c3b2a1/test"),
|
|
|
|
},
|
|
|
|
Output: []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"stage_name": "dev",
|
|
|
|
"rest_api_id": "a1b2c3d4e5",
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"stage_name": "test",
|
|
|
|
"rest_api_id": "e5d4c3b2a1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
output := flattenApiGatewayStageKeys(tc.Input)
|
|
|
|
if !reflect.DeepEqual(output, tc.Output) {
|
|
|
|
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 12:21:47 +02:00
|
|
|
}
|
2016-03-15 08:20:50 +01:00
|
|
|
|
|
|
|
func TestExpandPolicyAttributes(t *testing.T) {
|
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "Protocol-TLSv1",
|
|
|
|
"value": "false",
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "Protocol-TLSv1.1",
|
|
|
|
"value": "false",
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "Protocol-TLSv1.2",
|
|
|
|
"value": "true",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
attributes, err := expandPolicyAttributes(expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(attributes) != 3 {
|
2016-03-15 20:49:50 +01:00
|
|
|
t.Fatalf("expected number of attributes to be 3, but got %d", len(attributes))
|
2016-03-15 08:20:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := &elb.PolicyAttribute{
|
|
|
|
AttributeName: aws.String("Protocol-TLSv1.2"),
|
|
|
|
AttributeValue: aws.String("true"),
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(attributes[2], expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
attributes[2],
|
|
|
|
expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExpandPolicyAttributes_invalid(t *testing.T) {
|
|
|
|
expanded := []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "Protocol-TLSv1.2",
|
|
|
|
"value": "true",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
attributes, err := expandPolicyAttributes(expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &elb.PolicyAttribute{
|
|
|
|
AttributeName: aws.String("Protocol-TLSv1.2"),
|
|
|
|
AttributeValue: aws.String("false"),
|
|
|
|
}
|
|
|
|
|
|
|
|
if reflect.DeepEqual(attributes[0], expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
attributes[0],
|
|
|
|
expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExpandPolicyAttributes_empty(t *testing.T) {
|
|
|
|
var expanded []interface{}
|
|
|
|
|
|
|
|
attributes, err := expandPolicyAttributes(expanded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(attributes) != 0 {
|
2016-03-15 20:49:50 +01:00
|
|
|
t.Fatalf("expected number of attributes to be 0, but got %d", len(attributes))
|
2016-03-15 08:20:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFlattenPolicyAttributes(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Input []*elb.PolicyAttributeDescription
|
|
|
|
Output []interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Input: []*elb.PolicyAttributeDescription{
|
|
|
|
&elb.PolicyAttributeDescription{
|
|
|
|
AttributeName: aws.String("Protocol-TLSv1.2"),
|
|
|
|
AttributeValue: aws.String("true"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Output: []interface{}{
|
|
|
|
map[string]string{
|
|
|
|
"name": "Protocol-TLSv1.2",
|
|
|
|
"value": "true",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
output := flattenPolicyAttributes(tc.Input)
|
|
|
|
if !reflect.DeepEqual(output, tc.Output) {
|
|
|
|
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-17 20:50:38 +02:00
|
|
|
|
|
|
|
func TestNormalizeJsonString(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var actual string
|
|
|
|
|
|
|
|
// Well formatted and valid.
|
|
|
|
validJson := `{
|
|
|
|
"abc": {
|
|
|
|
"def": 123,
|
|
|
|
"xyz": [
|
|
|
|
{
|
|
|
|
"a": "ホリネズミ"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"b": "1\\n2"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
expected := `{"abc":{"def":123,"xyz":[{"a":"ホリネズミ"},{"b":"1\\n2"}]}}`
|
|
|
|
|
|
|
|
actual, err = normalizeJsonString(validJson)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Expected not to throw an error while parsing JSON, but got: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("Got:\n\n%s\n\nExpected:\n\n%s\n", actual, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Well formatted but not valid,
|
|
|
|
// missing closing squre bracket.
|
|
|
|
invalidJson := `{
|
|
|
|
"abc": {
|
|
|
|
"def": 123,
|
|
|
|
"xyz": [
|
|
|
|
{
|
|
|
|
"a": "1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
actual, err = normalizeJsonString(invalidJson)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected to throw an error while parsing JSON, but got: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// We expect the invalid JSON to be shown back to us again.
|
|
|
|
if actual != invalidJson {
|
|
|
|
t.Fatalf("Got:\n\n%s\n\nExpected:\n\n%s\n", expected, invalidJson)
|
|
|
|
}
|
|
|
|
}
|