@@ -100,6 +100,38 @@ func TestTemplatedTopic(t *testing.T) {
100100 }
101101}
102102
103+ func TestFilter (t * testing.T ) {
104+ rulesText := `['foo{y="2"}','foo', 'bar{x="1"}',
105+ 'up{x="1",y="2"}', 'baz{key="valu
106+ e1;value2"}','bar{y="2"}']`
107+
108+ rules , _ := parseMatchList (rulesText )
109+ for _ , mf := range rules {
110+ match [mf .GetName ()] = mf
111+ }
112+ type TestCase struct {
113+ Name string
114+ Labels map [string ]string
115+ Expect bool
116+ }
117+
118+ testList := []TestCase {
119+ {Name : "foo" , Labels : map [string ]string {"z" : "3" }, Expect : true },
120+ {Name : "bar" , Labels : map [string ]string {"x" : "1" }, Expect : true },
121+ {Name : "bar" , Labels : map [string ]string {"x" : "2" }, Expect : false },
122+ {Name : "bar" , Labels : map [string ]string {"y" : "2" }, Expect : true },
123+ {Name : "bar" , Labels : map [string ]string {"y" : "1" }, Expect : false },
124+ {Name : "up" , Labels : map [string ]string {"x" : "1" , "y" : "2" }, Expect : true },
125+ {Name : "up" , Labels : map [string ]string {"x" : "1" , "y" : "2" , "z" : "3" }, Expect : true },
126+ {Name : "up" , Labels : map [string ]string {"x" : "2" , "y" : "1" }, Expect : false },
127+ {Name : "go" , Labels : map [string ]string {"x" : "1" , "y" : "2" }, Expect : false },
128+ }
129+
130+ for _ , tcase := range testList {
131+ assert .Equal (t , tcase .Expect , filter (tcase .Name , tcase .Labels ))
132+ }
133+ }
134+
103135func BenchmarkSerializeToAvroJSON (b * testing.B ) {
104136 serializer , _ := NewAvroJSONSerializer ("schemas/metric.avsc" )
105137 writeRequest := NewWriteRequest ()
0 commit comments