github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/builtin/providers/aws/network_acl_entry_test.go (about)

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