|
| 1 | +package config |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/percona/percona-backup-mongodb/pbm/storage/azure" |
| 7 | + "github.com/percona/percona-backup-mongodb/pbm/storage/gcs" |
| 8 | + "github.com/percona/percona-backup-mongodb/pbm/storage/s3" |
| 9 | +) |
| 10 | + |
| 11 | +func TestIsSameStorage(t *testing.T) { |
| 12 | + t.Run("S3", func(t *testing.T) { |
| 13 | + cfg := &s3.Config{ |
| 14 | + Region: "eu", |
| 15 | + EndpointURL: "ep.com", |
| 16 | + Bucket: "b1", |
| 17 | + Prefix: "p1", |
| 18 | + ForcePathStyle: boolPtr(true), |
| 19 | + Credentials: s3.Credentials{ |
| 20 | + AccessKeyID: "k1", |
| 21 | + SecretAccessKey: "k2", |
| 22 | + }, |
| 23 | + UploadPartSize: 1000, |
| 24 | + MaxUploadParts: 10001, |
| 25 | + StorageClass: "sc", |
| 26 | + |
| 27 | + InsecureSkipTLSVerify: false, |
| 28 | + } |
| 29 | + eq := &s3.Config{ |
| 30 | + Region: "eu", |
| 31 | + Bucket: "b1", |
| 32 | + Prefix: "p1", |
| 33 | + } |
| 34 | + if !cfg.IsSameStorage(eq) { |
| 35 | + t.Errorf("config storage should identify the same instance: cfg=%+v, eq=%+v", cfg, eq) |
| 36 | + } |
| 37 | + |
| 38 | + neq := cfg.Clone() |
| 39 | + neq.Region = "us" |
| 40 | + if cfg.IsSameStorage(neq) { |
| 41 | + t.Errorf("storage instances has different region: cfg=%+v, eq=%+v", cfg, neq) |
| 42 | + } |
| 43 | + |
| 44 | + neq = cfg.Clone() |
| 45 | + neq.Bucket = "b2" |
| 46 | + if cfg.IsSameStorage(neq) { |
| 47 | + t.Errorf("storage instances has different bucket: cfg=%+v, eq=%+v", cfg, neq) |
| 48 | + } |
| 49 | + |
| 50 | + neq = cfg.Clone() |
| 51 | + neq.Prefix = "p2" |
| 52 | + if cfg.IsSameStorage(neq) { |
| 53 | + t.Errorf("storage instances has different prefix: cfg=%+v, eq=%+v", cfg, neq) |
| 54 | + } |
| 55 | + }) |
| 56 | + |
| 57 | + t.Run("Azure", func(t *testing.T) { |
| 58 | + cfg := &azure.Config{ |
| 59 | + Account: "a1", |
| 60 | + Container: "c1", |
| 61 | + EndpointURL: "az.com", |
| 62 | + Prefix: "p1", |
| 63 | + Credentials: azure.Credentials{ |
| 64 | + Key: "k", |
| 65 | + }, |
| 66 | + } |
| 67 | + |
| 68 | + eq := &azure.Config{ |
| 69 | + Account: "a1", |
| 70 | + Container: "c1", |
| 71 | + Prefix: "p1", |
| 72 | + } |
| 73 | + if !cfg.IsSameStorage(eq) { |
| 74 | + t.Errorf("config storage should identify the same instance: cfg=%+v, eq=%+v", cfg, eq) |
| 75 | + } |
| 76 | + |
| 77 | + neq := cfg.Clone() |
| 78 | + neq.Account = "a2" |
| 79 | + if cfg.IsSameStorage(neq) { |
| 80 | + t.Errorf("storage instances has different account: cfg=%+v, eq=%+v", cfg, neq) |
| 81 | + } |
| 82 | + |
| 83 | + neq = cfg.Clone() |
| 84 | + neq.Container = "c2" |
| 85 | + if cfg.IsSameStorage(neq) { |
| 86 | + t.Errorf("storage instances has different container: cfg=%+v, eq=%+v", cfg, neq) |
| 87 | + } |
| 88 | + |
| 89 | + neq = cfg.Clone() |
| 90 | + neq.Prefix = "p2" |
| 91 | + if cfg.IsSameStorage(neq) { |
| 92 | + t.Errorf("storage instances has different prefix: cfg=%+v, eq=%+v", cfg, neq) |
| 93 | + } |
| 94 | + }) |
| 95 | + |
| 96 | + t.Run("GCS", func(t *testing.T) { |
| 97 | + cfg := &gcs.Config{ |
| 98 | + Bucket: "b1", |
| 99 | + Prefix: "p1", |
| 100 | + Credentials: gcs.Credentials{ |
| 101 | + PrivateKey: "abc", |
| 102 | + }, |
| 103 | + ChunkSize: 1000, |
| 104 | + } |
| 105 | + |
| 106 | + eq := &gcs.Config{ |
| 107 | + Bucket: "b1", |
| 108 | + Prefix: "p1", |
| 109 | + } |
| 110 | + if !cfg.IsSameStorage(eq) { |
| 111 | + t.Errorf("config storage should identify the same instance: cfg=%+v, eq=%+v", cfg, eq) |
| 112 | + } |
| 113 | + |
| 114 | + neq := cfg.Clone() |
| 115 | + neq.Bucket = "b2" |
| 116 | + if cfg.IsSameStorage(neq) { |
| 117 | + t.Errorf("storage instances has different bucket: cfg=%+v, eq=%+v", cfg, neq) |
| 118 | + } |
| 119 | + |
| 120 | + neq = cfg.Clone() |
| 121 | + neq.Prefix = "p2" |
| 122 | + if cfg.IsSameStorage(neq) { |
| 123 | + t.Errorf("storage instances has different prefix: cfg=%+v, eq=%+v", cfg, neq) |
| 124 | + } |
| 125 | + }) |
| 126 | +} |
| 127 | + |
| 128 | +func boolPtr(b bool) *bool { |
| 129 | + return &b |
| 130 | +} |
0 commit comments