99 "time"
1010
1111 "github.com/google/go-cmp/cmp"
12+ "github.com/percona/percona-backup-mongodb/pbm/storage/oss"
1213 "github.com/testcontainers/testcontainers-go"
1314 "github.com/testcontainers/testcontainers-go/modules/mongodb"
1415 "go.mongodb.org/mongo-driver/mongo"
@@ -43,9 +44,10 @@ func TestIsSameStorage(t *testing.T) {
4344 InsecureSkipTLSVerify : false ,
4445 }
4546 eq := & s3.Config {
46- Region : "eu" ,
47- Bucket : "b1" ,
48- Prefix : "p1" ,
47+ Region : "eu" ,
48+ Bucket : "b1" ,
49+ Prefix : "p1" ,
50+ EndpointURL : "ep.com" ,
4951 }
5052 if ! cfg .IsSameStorage (eq ) {
5153 t .Errorf ("config storage should identify the same instance: cfg=%+v, eq=%+v" , cfg , eq )
@@ -68,6 +70,12 @@ func TestIsSameStorage(t *testing.T) {
6870 if cfg .IsSameStorage (neq ) {
6971 t .Errorf ("storage instances has different prefix: cfg=%+v, eq=%+v" , cfg , neq )
7072 }
73+
74+ neq = cfg .Clone ()
75+ neq .EndpointURL = "ep2.com"
76+ if cfg .IsSameStorage (neq ) {
77+ t .Errorf ("storage instances has different EndpointURL: cfg=%+v, eq=%+v" , cfg , neq )
78+ }
7179 })
7280
7381 t .Run ("Azure" , func (t * testing.T ) {
@@ -82,9 +90,10 @@ func TestIsSameStorage(t *testing.T) {
8290 }
8391
8492 eq := & azure.Config {
85- Account : "a1" ,
86- Container : "c1" ,
87- Prefix : "p1" ,
93+ Account : "a1" ,
94+ Container : "c1" ,
95+ Prefix : "p1" ,
96+ EndpointURL : "az.com" ,
8897 }
8998 if ! cfg .IsSameStorage (eq ) {
9099 t .Errorf ("config storage should identify the same instance: cfg=%+v, eq=%+v" , cfg , eq )
@@ -107,6 +116,12 @@ func TestIsSameStorage(t *testing.T) {
107116 if cfg .IsSameStorage (neq ) {
108117 t .Errorf ("storage instances has different prefix: cfg=%+v, eq=%+v" , cfg , neq )
109118 }
119+
120+ neq = cfg .Clone ()
121+ neq .EndpointURL = "az2.com"
122+ if cfg .IsSameStorage (neq ) {
123+ t .Errorf ("storage instances has different EndpointURL: cfg=%+v, eq=%+v" , cfg , neq )
124+ }
110125 })
111126
112127 t .Run ("GCS" , func (t * testing.T ) {
@@ -217,6 +232,59 @@ func TestIsSameStorage(t *testing.T) {
217232 t .Errorf ("storage instances has different prefix: cfg=%+v, eq=%+v" , cfg , neq )
218233 }
219234 })
235+
236+ t .Run ("oss" , func (t * testing.T ) {
237+ cfg := & oss.Config {
238+ Region : "eu" ,
239+ EndpointURL : "ep.com" ,
240+ Bucket : "b1" ,
241+ Prefix : "p1" ,
242+ Credentials : oss.Credentials {
243+ AccessKeyID : "k1" ,
244+ AccessKeySecret : "k2" ,
245+ SecurityToken : "sect" ,
246+ },
247+ ConnectTimeout : 10 * time .Second ,
248+ UploadPartSize : 6 << 20 ,
249+ MaxObjSizeGB : floatPtr (1.1 ),
250+ Retryer : & oss.Retryer {},
251+ ServerSideEncryption : & oss.SSE {},
252+ }
253+ eq := & oss.Config {
254+ Region : "eu" ,
255+ EndpointURL : "ep.com" ,
256+ Bucket : "b1" ,
257+ Prefix : "p1" ,
258+ }
259+ if ! cfg .IsSameStorage (eq ) {
260+ t .Errorf ("config storage should identify the same instance: cfg=%+v, eq=%+v, diff=%s" ,
261+ cfg , eq , cmp .Diff (* cfg , * eq ))
262+ }
263+
264+ neq := cfg .Clone ()
265+ neq .Region = "us"
266+ if cfg .IsSameStorage (neq ) {
267+ t .Errorf ("storage instances has different region: cfg=%+v, eq=%+v" , cfg , neq )
268+ }
269+
270+ neq = cfg .Clone ()
271+ neq .EndpointURL = "ep2.com"
272+ if cfg .IsSameStorage (neq ) {
273+ t .Errorf ("storage instances has different EndpointURL: cfg=%+v, eq=%+v" , cfg , neq )
274+ }
275+
276+ neq = cfg .Clone ()
277+ neq .Bucket = "b2"
278+ if cfg .IsSameStorage (neq ) {
279+ t .Errorf ("storage instances has different bucket: cfg=%+v, eq=%+v" , cfg , neq )
280+ }
281+
282+ neq = cfg .Clone ()
283+ neq .Prefix = "p2"
284+ if cfg .IsSameStorage (neq ) {
285+ t .Errorf ("storage instances has different prefix: cfg=%+v, eq=%+v" , cfg , neq )
286+ }
287+ })
220288}
221289
222290func TestCastError (t * testing.T ) {
0 commit comments