github.com/thanos-io/thanos@v0.32.5/pkg/store/opts_test.go (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package store
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/efficientgo/core/testutil"
    10  )
    11  
    12  // Refer to https://github.com/prometheus/prometheus/issues/2651.
    13  func TestFindSetMatches(t *testing.T) {
    14  	cases := []struct {
    15  		pattern string
    16  		exp     []string
    17  	}{
    18  		// Simple sets.
    19  		{
    20  			pattern: "foo|bar|baz",
    21  			exp: []string{
    22  				"foo",
    23  				"bar",
    24  				"baz",
    25  			},
    26  		},
    27  		// Simple sets with group wrapper.
    28  		{
    29  			pattern: "(foo|bar|baz)",
    30  			exp: []string{
    31  				"foo",
    32  				"bar",
    33  				"baz",
    34  			},
    35  		},
    36  		// Simple sets containing escaped characters.
    37  		{
    38  			pattern: "fo\\.o|bar\\?|\\^baz",
    39  			exp: []string{
    40  				"fo.o",
    41  				"bar?",
    42  				"^baz",
    43  			},
    44  		},
    45  		// Simple sets containing special characters without escaping.
    46  		{
    47  			pattern: "fo.o|bar?|^baz",
    48  			exp:     nil,
    49  		},
    50  		{
    51  			pattern: "(fool|bar)|(baz)",
    52  			exp:     nil,
    53  		},
    54  		{
    55  			pattern: "foo\\|bar\\|baz",
    56  			exp: []string{
    57  				"foo|bar|baz",
    58  			},
    59  		},
    60  		// empty pattern
    61  		{
    62  			pattern: "",
    63  			exp:     nil,
    64  		},
    65  	}
    66  
    67  	for _, c := range cases {
    68  		matches := findSetMatches(c.pattern)
    69  		testutil.Equals(t, c.exp, matches)
    70  	}
    71  }