From 7ce3872942fa70acab77343fe7cd550c9804b63a Mon Sep 17 00:00:00 2001 From: Zhuoyuan Liu Date: Thu, 24 Aug 2023 12:56:54 +0200 Subject: [PATCH] added test for validateTemplate --- cmd/thanos/rule_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/thanos/rule_test.go b/cmd/thanos/rule_test.go index 5703c7b3ccf..bae59238695 100644 --- a/cmd/thanos/rule_test.go +++ b/cmd/thanos/rule_test.go @@ -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) + } +}