mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: test that no interpolation is done when there are no wildcards
This commit is contained in:
@@ -179,7 +179,7 @@ func interpolateFilterWildcards(value string) string {
|
|||||||
} else if matches == 1 && strings.HasSuffix(value, "*") {
|
} else if matches == 1 && strings.HasSuffix(value, "*") {
|
||||||
value = reverse(strings.Replace(reverse(value), "*", "", 1))
|
value = reverse(strings.Replace(reverse(value), "*", "", 1))
|
||||||
value = fmt.Sprintf(`starts_with("%s")`, value)
|
value = fmt.Sprintf(`starts_with("%s")`, value)
|
||||||
} else if matches == 1 {
|
} else if matches != 0 {
|
||||||
re := regexp.MustCompile(`[-\/^$+?.()|[\]{}]`)
|
re := regexp.MustCompile(`[-\/^$+?.()|[\]{}]`)
|
||||||
value = string(re.ReplaceAllFunc([]byte(value), func(in []byte) []byte {
|
value = string(re.ReplaceAllFunc([]byte(value), func(in []byte) []byte {
|
||||||
return []byte(strings.Replace(string(in), string(in), `\\`+string(in), 1))
|
return []byte(strings.Replace(string(in), string(in), `\\`+string(in), 1))
|
||||||
|
@@ -398,7 +398,13 @@ func TestStackdriver(t *testing.T) {
|
|||||||
value := interpolateFilterWildcards("us-ce*tral1-*")
|
value := interpolateFilterWildcards("us-ce*tral1-*")
|
||||||
So(value, ShouldEqual, `monitoring.regex.full_match("^us\\-ce.*tral1\\-.*$")`)
|
So(value, ShouldEqual, `monitoring.regex.full_match("^us\\-ce.*tral1\\-.*$")`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("and no wildcard is used", func() {
|
||||||
|
value := interpolateFilterWildcards("us-central1-a}")
|
||||||
|
So(value, ShouldEqual, `us-central1-a}`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user