github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/chunk/opts_test.go (about) 1 package chunk 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 // Refer to https://github.com/prometheus/prometheus/issues/2651. 10 func TestFindSetMatches(t *testing.T) { 11 cases := []struct { 12 pattern string 13 exp []string 14 }{ 15 // Simple sets. 16 { 17 pattern: "foo|bar|baz", 18 exp: []string{ 19 "foo", 20 "bar", 21 "baz", 22 }, 23 }, 24 // Simple sets containing escaped characters. 25 { 26 pattern: "fo\\.o|bar\\?|\\^baz", 27 exp: []string{ 28 "fo.o", 29 "bar?", 30 "^baz", 31 }, 32 }, 33 // Simple sets containing special characters without escaping. 34 { 35 pattern: "fo.o|bar?|^baz", 36 exp: nil, 37 }, 38 { 39 pattern: "foo\\|bar\\|baz", 40 exp: []string{ 41 "foo|bar|baz", 42 }, 43 }, 44 } 45 46 for _, c := range cases { 47 matches := FindSetMatches(c.pattern) 48 require.Equal(t, c.exp, matches) 49 } 50 }