소스 검색

stackdriver: add tests from regex matching

Erik Sundell 7 년 전
부모
커밋
7e6a5c0a74
1개의 변경된 파일22개의 추가작업 그리고 7개의 파일을 삭제
  1. 22 7
      pkg/tsdb/stackdriver/stackdriver_test.go

+ 22 - 7
pkg/tsdb/stackdriver/stackdriver_test.go

@@ -406,16 +406,31 @@ func TestStackdriver(t *testing.T) {
 		})
 		})
 
 
 		Convey("when building filter string", func() {
 		Convey("when building filter string", func() {
-			Convey("and there are wildcards in a filter value", func() {
-				filterParts := []interface{}{"zone", "=", "*-central1*"}
-				value := buildFilterString("somemetrictype", filterParts)
-				So(value, ShouldEqual, `metric.type="somemetrictype" zone=has_substring("-central1")`)
+			Convey("and theres no regex operator", func() {
+				Convey("and there are wildcards in a filter value", func() {
+					filterParts := []interface{}{"zone", "=", "*-central1*"}
+					value := buildFilterString("somemetrictype", filterParts)
+					So(value, ShouldEqual, `metric.type="somemetrictype" zone=has_substring("-central1")`)
+				})
+
+				Convey("and there are no wildcards in any filter value", func() {
+					filterParts := []interface{}{"zone", "!=", "us-central1-a"}
+					value := buildFilterString("somemetrictype", filterParts)
+					So(value, ShouldEqual, `metric.type="somemetrictype" zone!="us-central1-a"`)
+				})
 			})
 			})
 
 
-			Convey("and there are no wildcards in any filter value", func() {
-				filterParts := []interface{}{"zone", "=", "us-central1-a"}
+			Convey("and there is a regex operator", func() {
+				filterParts := []interface{}{"zone", "=~", "us-central1-a~"}
 				value := buildFilterString("somemetrictype", filterParts)
 				value := buildFilterString("somemetrictype", filterParts)
-				So(value, ShouldEqual, `metric.type="somemetrictype" zone="us-central1-a"`)
+				Convey("it should remove the ~ character from the operator that belongs to the value", func() {
+					So(value, ShouldNotContainSubstring, `=~`)
+					So(value, ShouldContainSubstring, `zone=`)
+				})
+
+				Convey("it should insert monitoring.regex.full_match before filter value", func() {
+					So(value, ShouldContainSubstring, `zone=monitoring.regex.full_match("us-central1-a~")`)
+				})
 			})
 			})
 		})
 		})
 	})
 	})