@@ -64,3 +64,77 @@ func Test_S3Path_Parse(t *testing.T) {
64
64
}
65
65
}
66
66
}
67
+
68
+ func TestGetHTTPsUrl (t * testing.T ) {
69
+ grid := []struct {
70
+ Path string
71
+ Dualstack bool
72
+ Region string
73
+ ExpectedURL string
74
+ }{
75
+ {
76
+ Path : "s3://bucket" ,
77
+ Region : "us-east-1" ,
78
+ ExpectedURL : "https://bucket.s3.us-east-1.amazonaws.com" ,
79
+ },
80
+ {
81
+ Path : "s3://bucket.with.forced.path.style/subpath" ,
82
+ Region : "us-east-1" ,
83
+ ExpectedURL : "https://s3.us-east-1.amazonaws.com/bucket.with.forced.path.style/subpath" ,
84
+ },
85
+ {
86
+ Path : "s3://bucket/path" ,
87
+ Region : "us-east-2" ,
88
+ ExpectedURL : "https://bucket.s3.us-east-2.amazonaws.com/path" ,
89
+ },
90
+ {
91
+ Path : "s3://bucket2/path/subpath" ,
92
+ Region : "us-east-1" ,
93
+ ExpectedURL : "https://bucket2.s3.us-east-1.amazonaws.com/path/subpath" ,
94
+ },
95
+ {
96
+ Path : "s3://bucket2-ds/path/subpath" ,
97
+ Dualstack : true ,
98
+ Region : "us-east-1" ,
99
+ ExpectedURL : "https://bucket2-ds.s3.dualstack.us-east-1.amazonaws.com/path/subpath" ,
100
+ },
101
+ {
102
+ Path : "s3://bucket2-cn/path/subpath" ,
103
+ Region : "cn-north-1" ,
104
+ ExpectedURL : "https://bucket2-cn.s3.cn-north-1.amazonaws.com.cn/path/subpath" ,
105
+ },
106
+ {
107
+ Path : "s3://bucket2-cn-ds/path/subpath" ,
108
+ Dualstack : true ,
109
+ Region : "cn-north-1" ,
110
+ ExpectedURL : "https://bucket2-cn-ds.s3.dualstack.cn-north-1.amazonaws.com.cn/path/subpath" ,
111
+ },
112
+ {
113
+ Path : "s3://bucket2-gov/path/subpath" ,
114
+ Region : "us-gov-west-1" ,
115
+ ExpectedURL : "https://bucket2-gov.s3.us-gov-west-1.amazonaws.com/path/subpath" ,
116
+ },
117
+ {
118
+ Path : "s3://bucket2-gov-ds/path/subpath" ,
119
+ Dualstack : true ,
120
+ Region : "us-gov-west-1" ,
121
+ ExpectedURL : "https://bucket2-gov-ds.s3.dualstack.us-gov-west-1.amazonaws.com/path/subpath" ,
122
+ },
123
+ }
124
+ for _ , g := range grid {
125
+ t .Run (g .Path , func (t * testing.T ) {
126
+ // Must be nonempty in order to force S3_REGION usage
127
+ // rather than querying S3 for the region.
128
+ t .Setenv ("S3_ENDPOINT" , "1" )
129
+ t .Setenv ("S3_REGION" , g .Region )
130
+ s3path , _ := Context .buildS3Path (g .Path )
131
+ url , err := s3path .GetHTTPsUrl (g .Dualstack )
132
+ if err != nil {
133
+ t .Fatalf ("unexpected error: %v" , err )
134
+ }
135
+ if url != g .ExpectedURL {
136
+ t .Fatalf ("expected url: %v vs actual url: %v" , g .ExpectedURL , url )
137
+ }
138
+ })
139
+ }
140
+ }
0 commit comments