github.com/thanos-io/thanos@v0.32.5/internal/cortex/chunk/cache/cache_gen_test.go (about) 1 // Copyright (c) The Cortex Authors. 2 // Licensed under the Apache License 2.0. 3 4 package cache 5 6 import ( 7 "context" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestCacheGenNumCacheKeysPrefix(t *testing.T) { 14 keys := []string{"foo", "bar", "baz"} 15 16 for _, tc := range []struct { 17 name string 18 prefix string 19 }{ 20 { 21 name: "empty-prefix", 22 }, 23 { 24 name: "with-prefix", 25 prefix: "prefix", 26 }, 27 } { 28 t.Run(tc.name, func(t *testing.T) { 29 ctx := InjectCacheGenNumber(context.Background(), tc.prefix) 30 31 prefixedKeys := addCacheGenNumToCacheKeys(ctx, keys) 32 for i, key := range prefixedKeys { 33 require.Equal(t, tc.prefix+keys[i], key) 34 } 35 require.Len(t, prefixedKeys, len(keys)) 36 37 unprefixedKeys := removeCacheGenNumFromKeys(ctx, prefixedKeys) 38 for i, key := range unprefixedKeys { 39 require.Equal(t, keys[i], key) 40 } 41 require.Len(t, unprefixedKeys, len(keys)) 42 }) 43 } 44 }