Skip to content

Commit

Permalink
added test for validateTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuoyuan-liu committed Aug 24, 2023
1 parent 5e274da commit 7ce3872
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/thanos/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,27 @@ func Test_parseFlagLabels(t *testing.T) {
testutil.Equals(t, err != nil, td.expectErr)
}
}

func Test_validateTemplate(t *testing.T) {
tData := []struct {
template string
expectErr bool
}{
{
template: `/graph?g0.expr={{.Expr}}&g0.tab=1`,
expectErr: false,
},
{
template: `/graph?g0.expr={{.Expression}}&g0.tab=1`,
expectErr: true,
},
{
template: `another template includes {{.Expr}}`,
expectErr: false,
},
}
for _, td := range tData {
err := validateTemplate(td.template, Expression{Expr: "test_expr"})
testutil.Equals(t, err != nil, td.expectErr)
}
}

0 comments on commit 7ce3872

Please sign in to comment.