github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/validators_test.go (about) 1 package opc 2 3 import "testing" 4 5 func TestValidateIPPrefixCIDR(t *testing.T) { 6 validPrefixes := []string{ 7 "10.0.1.0/24", 8 "10.1.0.0/16", 9 "192.168.0.1/32", 10 "10.20.0.0/18", 11 "10.0.12.0/24", 12 } 13 14 for _, v := range validPrefixes { 15 _, errors := validateIPPrefixCIDR(v, "prefix") 16 if len(errors) != 0 { 17 t.Fatalf("%q should be a valid IP Address Prefix: %q", v, errors) 18 } 19 } 20 21 invalidPrefixes := []string{ 22 "10.0.0.1/35", 23 "192.168.1.256/16", 24 "256.0.1/16", 25 } 26 27 for _, v := range invalidPrefixes { 28 _, errors := validateIPPrefixCIDR(v, "prefix") 29 if len(errors) == 0 { 30 t.Fatalf("%q should not be a valid IP Address", v) 31 } 32 } 33 } 34 35 func TestValidateAdminDistance(t *testing.T) { 36 validDistances := []int{ 37 0, 38 1, 39 2, 40 } 41 42 for _, v := range validDistances { 43 _, errors := validateAdminDistance(v, "distance") 44 if len(errors) != 0 { 45 t.Fatalf("%q should be a valid Admin Distance: %q", v, errors) 46 } 47 } 48 49 invalidDistances := []int{ 50 -1, 51 4, 52 3, 53 42, 54 } 55 56 for _, v := range invalidDistances { 57 _, errors := validateAdminDistance(v, "distance") 58 if len(errors) == 0 { 59 t.Fatalf("%q should not be a valid Admin Distance", v) 60 } 61 } 62 } 63 64 func TestValidateIPProtocol(t *testing.T) { 65 validProtocols := []string{ 66 "all", 67 "ah", 68 "esp", 69 "icmp", 70 "icmpv6", 71 "igmp", 72 "ipip", 73 "gre", 74 "mplsip", 75 "ospf", 76 "pim", 77 "rdp", 78 "sctp", 79 "tcp", 80 "udp", 81 } 82 83 for _, v := range validProtocols { 84 _, errors := validateIPProtocol(v, "ip_protocol") 85 if len(errors) != 0 { 86 t.Fatalf("%q should be a valid Admin Distance: %q", v, errors) 87 } 88 } 89 90 invalidProtocols := []string{ 91 "bad", 92 "real bad", 93 "are you even trying at this point?", 94 } 95 for _, v := range invalidProtocols { 96 _, errors := validateIPProtocol(v, "ip_protocol") 97 if len(errors) == 0 { 98 t.Fatalf("%q should not be a valid IP Protocol", v) 99 } 100 } 101 102 }