MCPcopy
hub / github.com/minio/minio-go / TestGetEndpointURL

Function TestGetEndpointURL

utils_test.go:101–157  ·  view source on GitHub ↗

Tests for 'getEndpointURL(endpoint string, inSecure bool)'.

(t *testing.T)

Source from the content-addressed store, hash-verified

99
100// Tests for 'getEndpointURL(endpoint string, inSecure bool)'.
101func TestGetEndpointURL(t *testing.T) {
102 testCases := []struct {
103 // Inputs.
104 endPoint string
105 secure bool
106
107 // Expected result.
108 result string
109 err error
110 // Flag indicating whether the test is expected to pass or not.
111 shouldPass bool
112 }{
113 {"s3.amazonaws.com", true, "https://s3.amazonaws.com", nil, true},
114 {"s3.cn-north-1.amazonaws.com.cn", true, "https://s3.cn-north-1.amazonaws.com.cn", nil, true},
115 {"s3.cn-northwest-1.amazonaws.com.cn", true, "https://s3.cn-northwest-1.amazonaws.com.cn", nil, true},
116 {"s3.amazonaws.com", false, "http://s3.amazonaws.com", nil, true},
117 {"s3.cn-north-1.amazonaws.com.cn", false, "http://s3.cn-north-1.amazonaws.com.cn", nil, true},
118 {"s3.cn-northwest-1.amazonaws.com.cn", false, "http://s3.cn-northwest-1.amazonaws.com.cn", nil, true},
119 {"192.168.1.1:9000", false, "http://192.168.1.1:9000", nil, true},
120 {"192.168.1.1:9000", true, "https://192.168.1.1:9000", nil, true},
121 {"s3.amazonaws.com:443", true, "https://s3.amazonaws.com:443", nil, true},
122 {"storage.googleapis.com:443", true, "https://storage.googleapis.com:443", nil, true},
123 {"[::1]", false, "http://[::1]", nil, true},
124 {"[::1]", true, "https://[::1]", nil, true},
125 {"[::1]:80", false, "http://[::1]:80", nil, true},
126 {"[::1]:443", true, "https://[::1]:443", nil, true},
127 {"[::1]:9000", false, "http://[::1]:9000", nil, true},
128 {"[::1]:9000", true, "https://[::1]:9000", nil, true},
129 {"13333.123123.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "13333.123123.-")), false},
130 {"13333.123123.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "13333.123123.-")), false},
131 {"s3.aamzza.-", true, "", errInvalidArgument(fmt.Sprintf("Endpoint: %s does not follow ip address or domain name standards.", "s3.aamzza.-")), false},
132 {"", true, "", errInvalidArgument("Endpoint: does not follow ip address or domain name standards."), false},
133 }
134
135 for i, testCase := range testCases {
136 result, err := getEndpointURL(testCase.endPoint, testCase.secure)
137 if err != nil && testCase.shouldPass {
138 t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err.Error())
139 }
140 if err == nil && !testCase.shouldPass {
141 t.Errorf("Test %d: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, testCase.err.Error())
142 }
143 // Failed as expected, but does it fail for the expected reason.
144 if err != nil && !testCase.shouldPass {
145 if err.Error() != testCase.err.Error() {
146 t.Errorf("Test %d: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, testCase.err.Error(), err.Error())
147 }
148 }
149
150 // Test passes as expected, but the output values are verified for correctness here.
151 if err == nil && testCase.shouldPass {
152 if testCase.result != result.String() {
153 t.Errorf("Test %d: Expected the result Url to be \"%s\", but found \"%s\" instead", i+1, testCase.result, result.String())
154 }
155 }
156 }
157}
158

Callers

nothing calls this directly

Calls 4

errInvalidArgumentFunction · 0.85
getEndpointURLFunction · 0.85
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected