github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/azurerm/network_security_rule_test.go (about)

     1  package azurerm
     2  
     3  import "testing"
     4  
     5  func TestResourceAzureRMNetworkSecurityRuleProtocol_validation(t *testing.T) {
     6  	cases := []struct {
     7  		Value    string
     8  		ErrCount int
     9  	}{
    10  		{
    11  			Value:    "Random",
    12  			ErrCount: 1,
    13  		},
    14  		{
    15  			Value:    "tcp",
    16  			ErrCount: 0,
    17  		},
    18  		{
    19  			Value:    "TCP",
    20  			ErrCount: 0,
    21  		},
    22  		{
    23  			Value:    "*",
    24  			ErrCount: 0,
    25  		},
    26  		{
    27  			Value:    "Udp",
    28  			ErrCount: 0,
    29  		},
    30  		{
    31  			Value:    "Tcp",
    32  			ErrCount: 0,
    33  		},
    34  	}
    35  
    36  	for _, tc := range cases {
    37  		_, errors := validateNetworkSecurityRuleProtocol(tc.Value, "azurerm_network_security_rule")
    38  
    39  		if len(errors) != tc.ErrCount {
    40  			t.Fatalf("Expected the Azure RM Network Security Rule protocol to trigger a validation error")
    41  		}
    42  	}
    43  }
    44  
    45  func TestResourceAzureRMNetworkSecurityRuleAccess_validation(t *testing.T) {
    46  	cases := []struct {
    47  		Value    string
    48  		ErrCount int
    49  	}{
    50  		{
    51  			Value:    "Random",
    52  			ErrCount: 1,
    53  		},
    54  		{
    55  			Value:    "Allow",
    56  			ErrCount: 0,
    57  		},
    58  		{
    59  			Value:    "Deny",
    60  			ErrCount: 0,
    61  		},
    62  		{
    63  			Value:    "ALLOW",
    64  			ErrCount: 0,
    65  		},
    66  		{
    67  			Value:    "deny",
    68  			ErrCount: 0,
    69  		},
    70  	}
    71  
    72  	for _, tc := range cases {
    73  		_, errors := validateNetworkSecurityRuleAccess(tc.Value, "azurerm_network_security_rule")
    74  
    75  		if len(errors) != tc.ErrCount {
    76  			t.Fatalf("Expected the Azure RM Network Security Rule access to trigger a validation error")
    77  		}
    78  	}
    79  }
    80  
    81  func TestResourceAzureRMNetworkSecurityRuleDirection_validation(t *testing.T) {
    82  	cases := []struct {
    83  		Value    string
    84  		ErrCount int
    85  	}{
    86  		{
    87  			Value:    "Random",
    88  			ErrCount: 1,
    89  		},
    90  		{
    91  			Value:    "Inbound",
    92  			ErrCount: 0,
    93  		},
    94  		{
    95  			Value:    "Outbound",
    96  			ErrCount: 0,
    97  		},
    98  		{
    99  			Value:    "INBOUND",
   100  			ErrCount: 0,
   101  		},
   102  		{
   103  			Value:    "Inbound",
   104  			ErrCount: 0,
   105  		},
   106  	}
   107  
   108  	for _, tc := range cases {
   109  		_, errors := validateNetworkSecurityRuleDirection(tc.Value, "azurerm_network_security_rule")
   110  
   111  		if len(errors) != tc.ErrCount {
   112  			t.Fatalf("Expected the Azure RM Network Security Rule direction to trigger a validation error")
   113  		}
   114  	}
   115  }