Skip to content

Commit 4836732

Browse files
committedJan 13, 2025··
preserve error message
1 parent 8a9c471 commit 4836732

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed
 

‎get_s3.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (g *S3Getter) parseUrl(u *url.URL) (region, bucket, path, version string, c
313313
} else {
314314
pathParts := strings.SplitN(u.Path, "/", 3)
315315
if len(pathParts) != 3 {
316-
err = fmt.Errorf("URL is not a valid S3 URL")
316+
err = fmt.Errorf("URL is not a valid S3 compliant URL")
317317
return
318318
}
319319
bucket = pathParts[1]

‎get_s3_test.go

+21-15
Original file line numberDiff line numberDiff line change
@@ -278,43 +278,49 @@ func TestS3Getter_Url(t *testing.T) {
278278

279279
func Test_S3Getter_ParseUrl_Malformed(t *testing.T) {
280280
tests := []struct {
281-
name string
282-
url string
281+
name string
282+
input string
283+
expected string
283284
}{
284285
{
285-
name: "path style",
286-
url: "https://s3.amazonaws.com/bucket",
286+
name: "path style",
287+
input: "https://s3.amazonaws.com/bucket",
288+
expected: "URL is not a valid S3 URL",
287289
},
288290
{
289-
name: "vhost-style, dash region indication",
290-
url: "https://bucket.s3-us-east-1.amazonaws.com",
291+
name: "vhost-style, dash region indication",
292+
input: "https://bucket.s3-us-east-1.amazonaws.com",
293+
expected: "URL is not a valid S3 URL",
291294
},
292295
{
293-
name: "vhost-style, dot region indication",
294-
url: "https://bucket.s3.us-east-1.amazonaws.com",
296+
name: "vhost-style, dot region indication",
297+
input: "https://bucket.s3.us-east-1.amazonaws.com",
298+
expected: "URL is not a valid S3 URL",
295299
},
296300
{
297-
name: "invalid host parts",
298-
url: "https://invalid.host.parts.lenght.s3.us-east-1.amazonaws.com",
301+
name: "invalid host parts",
302+
input: "https://invalid.host.parts.lenght.s3.us-east-1.amazonaws.com",
303+
expected: "URL is not a valid S3 URL",
299304
},
300305
{
301-
name: "invalid host suffix",
302-
url: "https://bucket.s3.amazonaws.com.invalid",
306+
name: "invalid host suffix",
307+
input: "https://bucket.s3.amazonaws.com.invalid",
308+
expected: "URL is not a valid S3 compliant URL",
303309
},
304310
}
305311
for _, tt := range tests {
306312
t.Run(tt.name, func(t *testing.T) {
307313
g := new(S3Getter)
308-
u, err := url.Parse(tt.url)
314+
u, err := url.Parse(tt.input)
309315
if err != nil {
310316
t.Fatalf("unexpected error: %s", err)
311317
}
312318
_, _, _, _, _, err = g.parseUrl(u)
313319
if err == nil {
314320
t.Fatalf("expected error, got none")
315321
}
316-
if err.Error() != "URL is not a valid S3 URL" {
317-
t.Fatalf("expected error 'URL is not a valid S3 URL', got %s", err.Error())
322+
if err.Error() != tt.expected {
323+
t.Fatalf("expected error '%s', got %s for %s", tt.expected, err.Error(), tt.name)
318324
}
319325
})
320326
}

0 commit comments

Comments
 (0)
Please sign in to comment.