github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/clients/pkg/promtail/client/config_test.go (about) 1 package client 2 3 import ( 4 "net/url" 5 "reflect" 6 "testing" 7 "time" 8 9 "github.com/grafana/dskit/backoff" 10 "github.com/grafana/dskit/flagext" 11 "github.com/stretchr/testify/require" 12 13 "gopkg.in/yaml.v2" 14 ) 15 16 var clientConfig = Config{} 17 18 var clientDefaultConfig = (` 19 url: http://localhost:3100/loki/api/v1/push 20 `) 21 22 var clientCustomConfig = ` 23 url: http://localhost:3100/loki/api/v1/push 24 backoff_config: 25 max_retries: 20 26 min_period: 5s 27 max_period: 1m 28 batchwait: 5s 29 batchsize: 204800 30 timeout: 5s 31 ` 32 33 func Test_Config(t *testing.T) { 34 u, err := url.Parse("http://localhost:3100/loki/api/v1/push") 35 require.NoError(t, err) 36 tests := []struct { 37 configValues string 38 expectedConfig Config 39 }{ 40 { 41 clientDefaultConfig, 42 Config{ 43 URL: flagext.URLValue{ 44 URL: u, 45 }, 46 BackoffConfig: backoff.Config{ 47 MaxBackoff: MaxBackoff, 48 MaxRetries: MaxRetries, 49 MinBackoff: MinBackoff, 50 }, 51 BatchSize: BatchSize, 52 BatchWait: BatchWait, 53 Timeout: Timeout, 54 }, 55 }, 56 { 57 clientCustomConfig, 58 Config{ 59 URL: flagext.URLValue{ 60 URL: u, 61 }, 62 BackoffConfig: backoff.Config{ 63 MaxBackoff: 1 * time.Minute, 64 MaxRetries: 20, 65 MinBackoff: 5 * time.Second, 66 }, 67 BatchSize: 100 * 2048, 68 BatchWait: 5 * time.Second, 69 Timeout: 5 * time.Second, 70 }, 71 }, 72 } 73 for _, tc := range tests { 74 err := yaml.Unmarshal([]byte(tc.configValues), &clientConfig) 75 require.NoError(t, err) 76 77 if !reflect.DeepEqual(tc.expectedConfig, clientConfig) { 78 t.Errorf("Configs does not match, expected: %v, received: %v", tc.expectedConfig, clientConfig) 79 } 80 } 81 }