Skip to content

Commit

Permalink
fix: add test case (#2307)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss authored Aug 21, 2023
1 parent 11d1d81 commit c4f3ba2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/tools/grafana/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ func checkDashboardForDatasource(t *testing.T, path string, data []byte) {

// Check that the variable DS_PROMETHEUS exist
doesDsPromExist := false
// This is a list of names that are exempt from the check for a 'true' selected status.
excludedNames := []string{"TopResources", "Interval", "IncludeRoot"}

gjson.GetBytes(data, "templating.list").ForEach(func(key, value gjson.Result) bool {
name := value.Get("name").String()
if value.Get("name").String() == "DS_PROMETHEUS" {
doesDsPromExist = true
query := value.Get("query").String()
Expand All @@ -176,6 +180,19 @@ func checkDashboardForDatasource(t *testing.T, path string, data []byte) {
t.Errorf("dashboard=%s var=DS_PROMETHEUS type want=datasource got=%s", path, theType)
}
}

if !slices.Contains(excludedNames, name) {
if value.Get("current.selected").String() == "true" {
t.Errorf(
"dashboard=%s var=current.selected query want=false got=%s text=%s value=%s name= %s",
path,
"true",
value.Get("current.text"),
value.Get("current.value"),
name,
)
}
}
return true
})
if !doesDsPromExist {
Expand Down

0 comments on commit c4f3ba2

Please sign in to comment.