github.com/grafana/pyroscope@v1.18.0/pkg/objstore/providers/cos/config_test.go (about) 1 package cos 2 3 import ( 4 "testing" 5 6 "github.com/grafana/dskit/flagext" 7 ) 8 9 func TestConfig_Validate(t *testing.T) { 10 type fields struct { 11 Bucket string 12 Region string 13 AppID string 14 Endpoint string 15 SecretKey flagext.Secret 16 SecretID string 17 HTTP HTTPConfig 18 } 19 tests := []struct { 20 name string 21 fields fields 22 wantErr bool 23 }{ 24 { 25 name: "ok endpoint", 26 fields: fields{ 27 Endpoint: "http://bucket-123.cos.ap-beijing.myqcloud.com", 28 SecretID: "sid", 29 SecretKey: flagext.SecretWithValue("skey"), 30 }, 31 wantErr: false, 32 }, 33 { 34 name: "ok bucket-AppID-region", 35 fields: fields{ 36 Bucket: "bucket", 37 AppID: "123", 38 Region: "ap-beijing", 39 SecretID: "sid", 40 SecretKey: flagext.SecretWithValue("skey"), 41 }, 42 wantErr: false, 43 }, 44 { 45 name: "missing skey", 46 fields: fields{ 47 Bucket: "bucket", 48 AppID: "123", 49 Region: "ap-beijing", 50 }, 51 wantErr: true, 52 }, 53 { 54 name: "missing bucket", 55 fields: fields{ 56 AppID: "123", 57 Region: "ap-beijing", 58 SecretID: "sid", 59 SecretKey: flagext.SecretWithValue("skey"), 60 }, 61 wantErr: true, 62 }, 63 } 64 for _, tt := range tests { 65 t.Run(tt.name, func(t *testing.T) { 66 c := &Config{ 67 Bucket: tt.fields.Bucket, 68 Region: tt.fields.Region, 69 AppID: tt.fields.AppID, 70 Endpoint: tt.fields.Endpoint, 71 SecretKey: tt.fields.SecretKey, 72 SecretID: tt.fields.SecretID, 73 HTTP: tt.fields.HTTP, 74 } 75 if err := c.Validate(); (err != nil) != tt.wantErr { 76 t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) 77 } 78 }) 79 } 80 }