terraform/builtin/providers/aws/network_acl_entry_test.go

120 lines
2.2 KiB
Go
Raw Normal View History

package aws
import (
"reflect"
"testing"
"github.com/mitchellh/goamz/ec2"
)
func Test_expandNetworkAclEntry(t *testing.T) {
input := []interface{}{
map[string]interface{}{
2014-12-01 09:49:05 +01:00
"protocol": "tcp",
"from_port": 22,
"to_port": 22,
"cidr_block": "0.0.0.0/0",
2014-12-01 09:49:05 +01:00
"action": "deny",
"rule_no": 1,
},
map[string]interface{}{
2014-12-01 09:49:05 +01:00
"protocol": "tcp",
"from_port": 443,
"to_port": 443,
"cidr_block": "0.0.0.0/0",
2014-12-01 09:49:05 +01:00
"action": "deny",
"rule_no": 2,
},
}
2014-12-01 09:49:05 +01:00
expanded := expandNetworkAclEntries(input, "egress")
expected := []ec2.NetworkAclEntry{
ec2.NetworkAclEntry{
2014-12-01 09:49:05 +01:00
Protocol: 6,
PortRange: ec2.PortRange{
2014-12-01 09:49:05 +01:00
From: 22,
To: 22,
},
RuleAction: "deny",
RuleNumber: 1,
2014-12-01 09:49:05 +01:00
CidrBlock: "0.0.0.0/0",
Egress: true,
IcmpCode: ec2.IcmpCode{Code: 0, Type: 0},
},
ec2.NetworkAclEntry{
2014-12-01 09:49:05 +01:00
Protocol: 6,
PortRange: ec2.PortRange{
2014-12-01 09:49:05 +01:00
From: 443,
To: 443,
},
RuleAction: "deny",
RuleNumber: 2,
2014-12-01 09:49:05 +01:00
CidrBlock: "0.0.0.0/0",
Egress: true,
IcmpCode: ec2.IcmpCode{Code: 0, Type: 0},
},
2014-12-01 09:49:05 +01:00
}
if !reflect.DeepEqual(expanded, expected) {
t.Fatalf(
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
2014-12-01 09:49:05 +01:00
expanded,
expected)
}
}
func Test_flattenNetworkAclEntry(t *testing.T) {
2014-12-01 09:49:05 +01:00
apiInput := []ec2.NetworkAclEntry{
ec2.NetworkAclEntry{
2014-12-01 09:49:05 +01:00
Protocol: 6,
PortRange: ec2.PortRange{
2014-12-01 09:49:05 +01:00
From: 22,
To: 22,
},
RuleAction: "deny",
RuleNumber: 1,
2014-12-01 09:49:05 +01:00
CidrBlock: "0.0.0.0/0",
},
ec2.NetworkAclEntry{
2014-12-01 09:49:05 +01:00
Protocol: 6,
PortRange: ec2.PortRange{
2014-12-01 09:49:05 +01:00
From: 443,
To: 443,
},
RuleAction: "deny",
RuleNumber: 2,
2014-12-01 09:49:05 +01:00
CidrBlock: "0.0.0.0/0",
},
}
flattened := flattenNetworkAclEntries(apiInput)
expected := []map[string]interface{}{
2014-12-01 09:49:05 +01:00
map[string]interface{}{
"protocol": "tcp",
"from_port": 22,
"to_port": 22,
"cidr_block": "0.0.0.0/0",
2014-12-01 09:49:05 +01:00
"action": "deny",
"rule_no": 1,
},
map[string]interface{}{
2014-12-01 09:49:05 +01:00
"protocol": "tcp",
"from_port": 443,
"to_port": 443,
"cidr_block": "0.0.0.0/0",
2014-12-01 09:49:05 +01:00
"action": "deny",
"rule_no": 2,
},
}
if !reflect.DeepEqual(flattened, expected) {
t.Fatalf(
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
2014-12-01 09:49:05 +01:00
flattened[0],
expected)
}
}