github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/builtin/providers/aws/network_acl_entry_test.go (about) 1 package aws 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/hashicorp/aws-sdk-go/aws" 8 "github.com/hashicorp/aws-sdk-go/gen/ec2" 9 ) 10 11 func Test_expandNetworkACLEntry(t *testing.T) { 12 input := []interface{}{ 13 map[string]interface{}{ 14 "protocol": "tcp", 15 "from_port": 22, 16 "to_port": 22, 17 "cidr_block": "0.0.0.0/0", 18 "action": "deny", 19 "rule_no": 1, 20 }, 21 map[string]interface{}{ 22 "protocol": "tcp", 23 "from_port": 443, 24 "to_port": 443, 25 "cidr_block": "0.0.0.0/0", 26 "action": "deny", 27 "rule_no": 2, 28 }, 29 } 30 expanded, _ := expandNetworkAclEntries(input, "egress") 31 32 expected := []ec2.NetworkACLEntry{ 33 ec2.NetworkACLEntry{ 34 Protocol: aws.String("6"), 35 PortRange: &ec2.PortRange{ 36 From: aws.Integer(22), 37 To: aws.Integer(22), 38 }, 39 RuleAction: aws.String("deny"), 40 RuleNumber: aws.Integer(1), 41 CIDRBlock: aws.String("0.0.0.0/0"), 42 Egress: aws.Boolean(true), 43 }, 44 ec2.NetworkACLEntry{ 45 Protocol: aws.String("6"), 46 PortRange: &ec2.PortRange{ 47 From: aws.Integer(443), 48 To: aws.Integer(443), 49 }, 50 RuleAction: aws.String("deny"), 51 RuleNumber: aws.Integer(2), 52 CIDRBlock: aws.String("0.0.0.0/0"), 53 Egress: aws.Boolean(true), 54 }, 55 } 56 57 if !reflect.DeepEqual(expanded, expected) { 58 t.Fatalf( 59 "Got:\n\n%#v\n\nExpected:\n\n%#v\n", 60 expanded, 61 expected) 62 } 63 64 } 65 66 func Test_flattenNetworkACLEntry(t *testing.T) { 67 68 apiInput := []ec2.NetworkACLEntry{ 69 ec2.NetworkACLEntry{ 70 Protocol: aws.String("tcp"), 71 PortRange: &ec2.PortRange{ 72 From: aws.Integer(22), 73 To: aws.Integer(22), 74 }, 75 RuleAction: aws.String("deny"), 76 RuleNumber: aws.Integer(1), 77 CIDRBlock: aws.String("0.0.0.0/0"), 78 }, 79 ec2.NetworkACLEntry{ 80 Protocol: aws.String("tcp"), 81 PortRange: &ec2.PortRange{ 82 From: aws.Integer(443), 83 To: aws.Integer(443), 84 }, 85 RuleAction: aws.String("deny"), 86 RuleNumber: aws.Integer(2), 87 CIDRBlock: aws.String("0.0.0.0/0"), 88 }, 89 } 90 flattened := flattenNetworkAclEntries(apiInput) 91 92 expected := []map[string]interface{}{ 93 map[string]interface{}{ 94 "protocol": "tcp", 95 "from_port": 22, 96 "to_port": 22, 97 "cidr_block": "0.0.0.0/0", 98 "action": "deny", 99 "rule_no": 1, 100 }, 101 map[string]interface{}{ 102 "protocol": "tcp", 103 "from_port": 443, 104 "to_port": 443, 105 "cidr_block": "0.0.0.0/0", 106 "action": "deny", 107 "rule_no": 2, 108 }, 109 } 110 111 if !reflect.DeepEqual(flattened, expected) { 112 t.Fatalf( 113 "Got:\n\n%#v\n\nExpected:\n\n%#v\n", 114 flattened[0], 115 expected) 116 } 117 118 }