Commit 68332c59 by Erik Sundell

stackdriver: fix broken substring. also adds tests

parent 2e665fba
......@@ -170,8 +170,11 @@ func reverse(s string) string {
}
func interpolateFilterWildcards(value string) string {
if strings.HasSuffix(value, "*") && strings.HasPrefix(value, "*") {
value = strings.Replace(value, "*", "", 1)
re := regexp.MustCompile("[*]")
matches := re.FindAllStringIndex(value, -1)
logger.Info("len", "len", len(matches))
if len(matches) == 2 && strings.HasSuffix(value, "*") && strings.HasPrefix(value, "*") {
value = strings.Replace(value, "*", "", -1)
value = fmt.Sprintf(`has_substring("%s")`, value)
} else if strings.HasPrefix(value, "*") {
value = strings.Replace(value, "*", "", 1)
......
......@@ -342,6 +342,19 @@ func TestStackdriver(t *testing.T) {
})
})
})
Convey("when interpolating filter wildcards", func() {
Convey("and wildcard is used in the beginning and the end of the word", func() {
Convey("and theres no wildcard in the middle of the word", func() {
value := interpolateFilterWildcards("*-central1*")
So(value, ShouldEqual, `has_substring("-central1")`)
})
Convey("and there is a wildcard in the middle of the word", func() {
value := interpolateFilterWildcards("*-cent*ral1*")
So(value, ShouldNotStartWith, `has_substring`)
})
})
})
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment