(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestValidateAddress(t *testing.T) { |
| 55 | t.Run("IPv4", func(t *testing.T) { |
| 56 | testData := []struct { |
| 57 | name string |
| 58 | address string |
| 59 | err string |
| 60 | }{ |
| 61 | {"Valid without port", "190.0.0.1", "address 190.0.0.1: missing port in address"}, |
| 62 | {"Valid with port", "192.5.32.1:333", ""}, |
| 63 | {"Invalid without port", "12.0.0", "address 12.0.0: missing port in address"}, |
| 64 | // the following test returns true because 12.0.0 is considered as valid |
| 65 | // hostname |
| 66 | {"Valid with port", "12.0.0:3333", ""}, |
| 67 | {"Invalid port", "190.0.0.1:222222", "Invalid port: 222222"}, |
| 68 | } |
| 69 | for _, st := range testData { |
| 70 | t.Run(st.name, func(t *testing.T) { |
| 71 | if st.err != "" { |
| 72 | require.EqualError(t, ValidateAddress(st.address), st.err) |
| 73 | } else { |
| 74 | require.NoError(t, ValidateAddress(st.address)) |
| 75 | } |
| 76 | }) |
| 77 | } |
| 78 | |
| 79 | }) |
| 80 | t.Run("IPv6", func(t *testing.T) { |
| 81 | testData := []struct { |
| 82 | name string |
| 83 | address string |
| 84 | err string |
| 85 | }{ |
| 86 | {"Valid without port", "[2001:db8::1]", "address [2001:db8::1]: missing port in address"}, |
| 87 | {"Valid with port", "[2001:db8::1]:8888", ""}, |
| 88 | {"Invalid without port", "[2001:db8]", "address [2001:db8]: missing port in address"}, |
| 89 | {"Invalid with port", "[2001:db8]:2222", "Invalid hostname: 2001:db8"}, |
| 90 | {"Invalid port", "[2001:db8::1]:222222", "Invalid port: 222222"}, |
| 91 | } |
| 92 | for _, st := range testData { |
| 93 | t.Run(st.name, func(t *testing.T) { |
| 94 | if st.err != "" { |
| 95 | require.EqualError(t, ValidateAddress(st.address), st.err) |
| 96 | } else { |
| 97 | require.NoError(t, ValidateAddress(st.address)) |
| 98 | } |
| 99 | }) |
| 100 | } |
| 101 | }) |
| 102 | t.Run("Hostnames", func(t *testing.T) { |
| 103 | testData := []struct { |
| 104 | name string |
| 105 | address string |
| 106 | err string |
| 107 | }{ |
| 108 | {"Valid", "dgraph-alpha-0.dgraph-alpha-headless.default.svc.local:9080", ""}, |
| 109 | {"Valid with underscores", "alpha_1:9080", ""}, |
| 110 | {"Valid ending in a period", "dgraph-alpha-0.dgraph-alpha-headless.default.svc.:9080", ""}, |
| 111 | {"Invalid because the name part is longer than 63 characters", |
nothing calls this directly
no test coverage detected