Tests validate end point validator.
(t *testing.T)
| 158 | |
| 159 | // Tests validate end point validator. |
| 160 | func TestIsValidEndpointURL(t *testing.T) { |
| 161 | testCases := []struct { |
| 162 | url string |
| 163 | err error |
| 164 | // Flag indicating whether the test is expected to pass or not. |
| 165 | shouldPass bool |
| 166 | }{ |
| 167 | {"", errInvalidArgument("Endpoint url cannot be empty."), false}, |
| 168 | {"https://s3.amazonaws.com", nil, true}, |
| 169 | {"https://s3.cn-north-1.amazonaws.com.cn", nil, true}, |
| 170 | {"https://s3-us-gov-west-1.amazonaws.com", nil, true}, |
| 171 | {"https://s3-fips-us-gov-west-1.amazonaws.com", nil, true}, |
| 172 | {"https://s3-fips.us-gov-west-1.amazonaws.com", nil, true}, |
| 173 | {"https://s3-fips.us-gov-east-1.amazonaws.com", nil, true}, |
| 174 | {"https://s3.amazonaws.com/", nil, true}, |
| 175 | {"https://storage.googleapis.com/", nil, true}, |
| 176 | {"https://z3.amazonaws.com", nil, true}, |
| 177 | {"https://mybalancer.us-east-1.elb.amazonaws.com", nil, true}, |
| 178 | {"https://test-access-point-000000000000.op-00000000000000000.s3-outposts.eu-central-1.amazonaws.com", nil, true}, |
| 179 | {"192.168.1.1", errInvalidArgument("Endpoint url cannot have fully qualified paths."), false}, |
| 180 | {"https://amazon.googleapis.com/", errInvalidArgument("Google Cloud Storage endpoint should be 'storage.googleapis.com'."), false}, |
| 181 | {"https://storage.googleapis.com/bucket/", errInvalidArgument("Endpoint url cannot have fully qualified paths."), false}, |
| 182 | {"https://s3.amazonaws.com/bucket/object", errInvalidArgument("Endpoint url cannot have fully qualified paths."), false}, |
| 183 | {"https://.s3server.example.com/", errInvalidArgument("Endpoint: .s3server.example.com does not follow ip address or domain name standards."), false}, |
| 184 | {"https://s3server.example_/", errInvalidArgument("Endpoint: s3server.example_ does not follow ip address or domain name standards."), false}, |
| 185 | {"https://_s3server.example.com/", errInvalidArgument("Endpoint: _s3server.example.com does not follow ip address or domain name standards."), false}, |
| 186 | {"https://s3-outposts.eu-central-1.amazonaws.com", errInvalidArgument("S3 Outposts endpoint must match <prefix>.s3-outposts.<region>.amazonaws.com"), false}, |
| 187 | } |
| 188 | |
| 189 | for i, testCase := range testCases { |
| 190 | var u url.URL |
| 191 | if testCase.url == "" { |
| 192 | u = sentinelURL |
| 193 | } else { |
| 194 | u1, err := url.Parse(testCase.url) |
| 195 | if err != nil { |
| 196 | t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err) |
| 197 | } |
| 198 | u = *u1 |
| 199 | } |
| 200 | err := isValidEndpointURL(u) |
| 201 | if err != nil && testCase.shouldPass { |
| 202 | t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err) |
| 203 | } |
| 204 | if err == nil && !testCase.shouldPass { |
| 205 | t.Errorf("Test %d: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, testCase.err) |
| 206 | } |
| 207 | // Failed as expected, but does it fail for the expected reason. |
| 208 | if err != nil && !testCase.shouldPass { |
| 209 | if err.Error() != testCase.err.Error() { |
| 210 | t.Errorf("Test %d: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, testCase.err, err) |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | func TestDefaultBucketLocation(t *testing.T) { |
| 217 | testCases := []struct { |
nothing calls this directly
no test coverage detected