forked from hashicorp/go-getter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect_s3_test.go
89 lines (85 loc) · 2.01 KB
/
detect_s3_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package getter
import (
"testing"
)
func TestS3Detector(t *testing.T) {
cases := []struct {
Input string
Output string
}{
// Virtual hosted style
{
"bucket.s3.amazonaws.com/foo",
"s3::https://s3.amazonaws.com/bucket/foo",
},
{
"bucket.s3.amazonaws.com/foo/bar",
"s3::https://s3.amazonaws.com/bucket/foo/bar",
},
{
"bucket.s3.amazonaws.com/foo/bar.baz",
"s3::https://s3.amazonaws.com/bucket/foo/bar.baz",
},
{
"bucket.s3-eu-west-1.amazonaws.com/foo",
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo",
},
{
"bucket.s3-eu-west-1.amazonaws.com/foo/bar",
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo/bar",
},
{
"bucket.s3-eu-west-1.amazonaws.com/foo/bar.baz",
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo/bar.baz",
},
// 5 parts Virtual hosted-style
{
"bucket.s3.eu-west-1.amazonaws.com/foo/bar.baz",
"s3::https://s3.eu-west-1.amazonaws.com/bucket/foo/bar.baz",
},
// Path style
{
"s3.amazonaws.com/bucket/foo",
"s3::https://s3.amazonaws.com/bucket/foo",
},
{
"s3.amazonaws.com/bucket/foo/bar",
"s3::https://s3.amazonaws.com/bucket/foo/bar",
},
{
"s3.amazonaws.com/bucket/foo/bar.baz",
"s3::https://s3.amazonaws.com/bucket/foo/bar.baz",
},
{
"s3-eu-west-1.amazonaws.com/bucket/foo",
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo",
},
{
"s3-eu-west-1.amazonaws.com/bucket/foo/bar",
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo/bar",
},
{
"s3-eu-west-1.amazonaws.com/bucket/foo/bar.baz",
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo/bar.baz",
},
// Misc tests
{
"s3-eu-west-1.amazonaws.com/bucket/foo/bar.baz?version=1234",
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo/bar.baz?version=1234",
},
}
pwd := "/pwd"
f := new(S3Detector)
for i, tc := range cases {
output, ok, err := f.Detect(tc.Input, pwd)
if err != nil {
t.Fatalf("err: %s", err)
}
if !ok {
t.Fatal("not ok")
}
if output != tc.Output {
t.Fatalf("%d: bad: %#v", i, output)
}
}
}