github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/storage/tsdb/index_cache_test.go (about)

     1  package tsdb
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/grafana/dskit/flagext"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestIndexCacheConfig_Validate(t *testing.T) {
    11  	tests := map[string]struct {
    12  		cfg      IndexCacheConfig
    13  		expected error
    14  	}{
    15  		"default config should pass": {
    16  			cfg: func() IndexCacheConfig {
    17  				cfg := IndexCacheConfig{}
    18  				flagext.DefaultValues(&cfg)
    19  				return cfg
    20  			}(),
    21  		},
    22  		"unsupported backend should fail": {
    23  			cfg: IndexCacheConfig{
    24  				Backend: "xxx",
    25  			},
    26  			expected: errUnsupportedIndexCacheBackend,
    27  		},
    28  		"no memcached addresses should fail": {
    29  			cfg: IndexCacheConfig{
    30  				Backend: "memcached",
    31  			},
    32  			expected: errNoIndexCacheAddresses,
    33  		},
    34  		"one memcached address should pass": {
    35  			cfg: IndexCacheConfig{
    36  				Backend: "memcached",
    37  				Memcached: MemcachedClientConfig{
    38  					Addresses: "dns+localhost:11211",
    39  				},
    40  			},
    41  		},
    42  	}
    43  
    44  	for testName, testData := range tests {
    45  		t.Run(testName, func(t *testing.T) {
    46  			assert.Equal(t, testData.expected, testData.cfg.Validate())
    47  		})
    48  	}
    49  }