Remove empty tags 2 (#16113)
* Add support for RemoveEmptyTags in API client * Add changelog --------- Co-authored-by: Rémi Lapeyre <remi.lapeyre@lenstra.fr>
This commit is contained in:
parent
0f3e935228
commit
f36f888f55
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
client: add support for RemoveEmptyTags in Prepared Queries templates.
|
||||||
|
```
|
|
@ -96,6 +96,12 @@ type QueryTemplate struct {
|
||||||
// Regexp allows specifying a regex pattern to match against the name
|
// Regexp allows specifying a regex pattern to match against the name
|
||||||
// of the query being executed.
|
// of the query being executed.
|
||||||
Regexp string
|
Regexp string
|
||||||
|
|
||||||
|
// RemoveEmptyTags if set to true, will cause the Tags list inside
|
||||||
|
// the Service structure to be stripped of any empty strings. This is useful
|
||||||
|
// when interpolating into tags in a way where the tag is optional, and
|
||||||
|
// where searching for an empty tag would yield no results from the query.
|
||||||
|
RemoveEmptyTags bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreparedQueryDefinition defines a complete prepared query.
|
// PreparedQueryDefinition defines a complete prepared query.
|
||||||
|
|
|
@ -180,3 +180,55 @@ func TestAPI_PreparedQuery(t *testing.T) {
|
||||||
t.Fatalf("bad: %v", defs)
|
t.Fatalf("bad: %v", defs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAPI_PreparedQueryRemoveEmptyTags(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
c, s := makeClient(t)
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
def := &PreparedQueryDefinition{
|
||||||
|
Name: "test",
|
||||||
|
Service: ServiceQuery{
|
||||||
|
Service: "redis",
|
||||||
|
},
|
||||||
|
Template: QueryTemplate{
|
||||||
|
RemoveEmptyTags: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
query := c.PreparedQuery()
|
||||||
|
var err error
|
||||||
|
def.ID, _, err = query.Create(def, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
queries, _, err := query.Get(def.ID, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
if len(queries) != 1 {
|
||||||
|
t.Fatalf("wrong length: %#v", queries)
|
||||||
|
}
|
||||||
|
if queries[0].Template.RemoveEmptyTags {
|
||||||
|
t.Fatalf("wrong value: %v", queries[0].Template.RemoveEmptyTags)
|
||||||
|
}
|
||||||
|
|
||||||
|
def.Template.RemoveEmptyTags = true
|
||||||
|
_, err = query.Update(def, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
queries, _, err = query.Get(def.ID, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
if len(queries) != 1 {
|
||||||
|
t.Fatalf("wrong length: %#v", queries)
|
||||||
|
}
|
||||||
|
if !queries[0].Template.RemoveEmptyTags {
|
||||||
|
t.Fatalf("wrong value: %v", queries[0].Template.RemoveEmptyTags)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue