github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/bucket/azure/config_test.go (about) 1 package azure 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/grafana/dskit/flagext" 8 "github.com/stretchr/testify/require" 9 yaml "gopkg.in/yaml.v2" 10 11 "github.com/grafana/loki/pkg/storage/bucket/http" 12 ) 13 14 // defaultConfig should match the default flag values defined in RegisterFlagsWithPrefix. 15 var defaultConfig = Config{ 16 ContainerName: "loki", 17 MaxRetries: 20, 18 Config: http.Config{ 19 IdleConnTimeout: 90 * time.Second, 20 ResponseHeaderTimeout: 2 * time.Minute, 21 InsecureSkipVerify: false, 22 TLSHandshakeTimeout: 10 * time.Second, 23 ExpectContinueTimeout: 1 * time.Second, 24 MaxIdleConns: 100, 25 MaxIdleConnsPerHost: 100, 26 MaxConnsPerHost: 0, 27 }, 28 } 29 30 func TestConfig(t *testing.T) { 31 t.Parallel() 32 33 tests := map[string]struct { 34 config string 35 expectedConfig Config 36 expectedErr error 37 }{ 38 "default config": { 39 config: "", 40 expectedConfig: defaultConfig, 41 expectedErr: nil, 42 }, 43 "custom config": { 44 config: ` 45 account_name: test-account-name 46 account_key: test-account-key 47 container_name: test-container-name 48 endpoint_suffix: test-endpoint-suffix 49 max_retries: 1 50 http: 51 idle_conn_timeout: 2s 52 response_header_timeout: 3s 53 insecure_skip_verify: true 54 tls_handshake_timeout: 4s 55 expect_continue_timeout: 5s 56 max_idle_connections: 6 57 max_idle_connections_per_host: 7 58 max_connections_per_host: 8 59 `, 60 expectedConfig: Config{ 61 StorageAccountName: "test-account-name", 62 StorageAccountKey: flagext.SecretWithValue("test-account-key"), 63 ContainerName: "test-container-name", 64 Endpoint: "test-endpoint-suffix", 65 MaxRetries: 1, 66 Config: http.Config{ 67 IdleConnTimeout: 2 * time.Second, 68 ResponseHeaderTimeout: 3 * time.Second, 69 InsecureSkipVerify: true, 70 TLSHandshakeTimeout: 4 * time.Second, 71 ExpectContinueTimeout: 5 * time.Second, 72 MaxIdleConns: 6, 73 MaxIdleConnsPerHost: 7, 74 MaxConnsPerHost: 8, 75 }, 76 }, 77 expectedErr: nil, 78 }, 79 "invalid type": { 80 config: `max_retries: foo`, 81 expectedConfig: defaultConfig, 82 expectedErr: &yaml.TypeError{Errors: []string{"line 1: cannot unmarshal !!str `foo` into int"}}, 83 }, 84 } 85 86 for testName, testData := range tests { 87 testData := testData 88 89 t.Run(testName, func(t *testing.T) { 90 cfg := Config{} 91 flagext.DefaultValues(&cfg) 92 93 err := yaml.Unmarshal([]byte(testData.config), &cfg) 94 require.Equal(t, testData.expectedErr, err) 95 require.Equal(t, testData.expectedConfig, cfg) 96 }) 97 } 98 }