Path: blob/main/component/common/loki/client/config_test.go
4096 views
package client12// This code is copied from Promtail. The client package is used to configure3// and run the clients that can send log entries to a Loki instance.45import (6"net/url"7"reflect"8"testing"9"time"1011"github.com/grafana/dskit/backoff"12"github.com/grafana/dskit/flagext"13"github.com/stretchr/testify/require"1415"gopkg.in/yaml.v2"16)1718var clientConfig = Config{}1920var clientDefaultConfig = (`21url: http://localhost:3100/loki/api/v1/push22`)2324var clientCustomConfig = `25url: http://localhost:3100/loki/api/v1/push26backoff_config:27max_retries: 2028min_period: 5s29max_period: 1m30batchwait: 5s31batchsize: 20480032timeout: 5s33`3435func Test_Config(t *testing.T) {36u, err := url.Parse("http://localhost:3100/loki/api/v1/push")37require.NoError(t, err)38tests := []struct {39configValues string40expectedConfig Config41}{42{43clientDefaultConfig,44Config{45URL: flagext.URLValue{46URL: u,47},48BackoffConfig: backoff.Config{49MaxBackoff: MaxBackoff,50MaxRetries: MaxRetries,51MinBackoff: MinBackoff,52},53BatchSize: BatchSize,54BatchWait: BatchWait,55Timeout: Timeout,56},57},58{59clientCustomConfig,60Config{61URL: flagext.URLValue{62URL: u,63},64BackoffConfig: backoff.Config{65MaxBackoff: 1 * time.Minute,66MaxRetries: 20,67MinBackoff: 5 * time.Second,68},69BatchSize: 100 * 2048,70BatchWait: 5 * time.Second,71Timeout: 5 * time.Second,72},73},74}75for _, tc := range tests {76err := yaml.Unmarshal([]byte(tc.configValues), &clientConfig)77require.NoError(t, err)7879if !reflect.DeepEqual(tc.expectedConfig, clientConfig) {80t.Errorf("Configs does not match, expected: %v, received: %v", tc.expectedConfig, clientConfig)81}82}83}848586