github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/flameql/flameql_test.go (about) 1 package flameql 2 3 import ( 4 "errors" 5 6 . "github.com/onsi/ginkgo/v2" 7 . "github.com/onsi/gomega" 8 ) 9 10 var _ = Describe("TagMatcher", func() { 11 It("matches", func() { 12 type testCase struct { 13 matcher string 14 value string 15 matches bool 16 } 17 18 testCases := []testCase{ 19 {`foo="bar"`, "bar", true}, 20 {`foo="bar"`, "baz", false}, 21 {`foo!="bar"`, "bar", false}, 22 {`foo!="bar"`, "baz", true}, 23 {`foo=~"bar"`, "bar", true}, 24 {`foo=~"bar"`, "baz", false}, 25 {`foo!~"bar"`, "bar", false}, 26 {`foo!~"bar"`, "baz", true}, 27 } 28 29 for _, tc := range testCases { 30 m, err := ParseMatchers(tc.matcher) 31 Expect(err).ToNot(HaveOccurred()) 32 Expect(m[0].Match(tc.value)).To(Equal(tc.matches)) 33 } 34 }) 35 }) 36 37 var _ = Describe("ValidateTagKey", func() { 38 It("reports error if a key violates constraints", func() { 39 type testCase struct { 40 key string 41 err error 42 } 43 44 testCases := []testCase{ 45 {"foo_BAR_12_baz_qux", nil}, 46 47 {ReservedTagKeyName, ErrTagKeyReserved}, 48 {"", ErrTagKeyIsRequired}, 49 {"#", ErrInvalidTagKey}, 50 } 51 52 for _, tc := range testCases { 53 err := ValidateTagKey(tc.key) 54 if tc.err != nil { 55 Expect(errors.Is(err, tc.err)).To(BeTrue()) 56 continue 57 } 58 Expect(err).To(BeNil()) 59 } 60 }) 61 }) 62 63 var _ = Describe("ValidateAppName", func() { 64 It("reports error if an app name violates constraints", func() { 65 type testCase struct { 66 appName string 67 err error 68 } 69 70 testCases := []testCase{ 71 {"foo.BAR-1.2_baz_qux", nil}, 72 73 {"", ErrAppNameIsRequired}, 74 {"#", ErrInvalidAppName}, 75 } 76 77 for _, tc := range testCases { 78 err := ValidateAppName(tc.appName) 79 if tc.err != nil { 80 Expect(errors.Is(err, tc.err)).To(BeTrue()) 81 continue 82 } 83 Expect(err).To(BeNil()) 84 } 85 }) 86 })