Skip to content

Commit f072793

Browse files
committed
tests: Delete unnecessary template prefix parameter
The template name doesn't need to be globally unique.
1 parent 5a35b9e commit f072793

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

internal/template/functions_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestKeys(t *testing.T) {
4747
{`{{range (keys $)}}{{.}}{{end}}`, env, `VIRTUAL_HOST`},
4848
}
4949

50-
tests.run(t, "keys")
50+
tests.run(t)
5151
}
5252

5353
func TestKeysEmpty(t *testing.T) {
@@ -116,7 +116,7 @@ func TestSplitN(t *testing.T) {
116116
{`{{len (splitN . "/" 2)}}`, "example.com", `1`},
117117
}
118118

119-
tests.run(t, "splitN")
119+
tests.run(t)
120120
}
121121

122122
func TestTrimPrefix(t *testing.T) {
@@ -250,7 +250,7 @@ func TestParseJson(t *testing.T) {
250250
{`{{index (parseJson . | first) "enabled"}}`, `[{"enabled":true}]`, `true`},
251251
}
252252

253-
tests.run(t, "parseJson")
253+
tests.run(t)
254254
}
255255

256256
func TestQueryEscape(t *testing.T) {
@@ -261,7 +261,7 @@ func TestQueryEscape(t *testing.T) {
261261
{`{{queryEscape .}}`, `~^example\.com(\..*\.xip\.io)?$`, `~%5Eexample%5C.com%28%5C..%2A%5C.xip%5C.io%29%3F%24`},
262262
}
263263

264-
tests.run(t, "queryEscape")
264+
tests.run(t)
265265
}
266266

267267
func TestArrayClosestExact(t *testing.T) {
@@ -299,7 +299,7 @@ func TestWhen(t *testing.T) {
299299
{`{{ when (not (eq .StringValue "foo")) "first" "second" | print }}`, context, `second`},
300300
}
301301

302-
tests.run(t, "when")
302+
tests.run(t)
303303
}
304304

305305
func TestWhenTrue(t *testing.T) {

internal/template/template_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package template
22

33
import (
44
"bytes"
5-
"fmt"
65
"reflect"
6+
"strconv"
77
"strings"
88
"testing"
9-
"text/template"
109

1110
"github.com/stretchr/testify/assert"
1211
)
@@ -17,23 +16,22 @@ type templateTestList []struct {
1716
expected string
1817
}
1918

20-
func (tests templateTestList) run(t *testing.T, prefix string) {
19+
func (tests templateTestList) run(t *testing.T) {
2120
for n, test := range tests {
2221
test := test
23-
tmplName := fmt.Sprintf("%s-test-%d", prefix, n)
24-
t.Run(tmplName, func(t *testing.T) {
22+
t.Run(strconv.Itoa(n), func(t *testing.T) {
2523
t.Parallel()
26-
tmpl := template.Must(newTemplate(tmplName).Parse(test.tmpl))
24+
tmpl := template.Must(newTemplate("testTemplate").Parse(test.tmpl))
2725

2826
var b bytes.Buffer
29-
err := tmpl.ExecuteTemplate(&b, tmplName, test.context)
27+
err := tmpl.ExecuteTemplate(&b, "testTemplate", test.context)
3028
if err != nil {
31-
t.Fatalf("Error executing template: %v (test %s)", err, tmplName)
29+
t.Fatalf("Error executing template: %v", err)
3230
}
3331

3432
got := b.String()
3533
if test.expected != got {
36-
t.Fatalf("Incorrect output found; expected %s, got %s (test %s)", test.expected, got, tmplName)
34+
t.Fatalf("Incorrect output found; expected %s, got %s", test.expected, got)
3735
}
3836
})
3937
}

internal/template/where_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestWhere(t *testing.T) {
6868
},
6969
}
7070

71-
tests.run(t, "where")
71+
tests.run(t)
7272
}
7373

7474
func TestWhereNot(t *testing.T) {
@@ -133,7 +133,7 @@ func TestWhereNot(t *testing.T) {
133133
},
134134
}
135135

136-
tests.run(t, "whereNot")
136+
tests.run(t)
137137
}
138138

139139
func TestWhereExist(t *testing.T) {
@@ -173,7 +173,7 @@ func TestWhereExist(t *testing.T) {
173173
{`{{whereExist . "Env.VIRTUAL_PROTO" | len}}`, containers, `1`},
174174
}
175175

176-
tests.run(t, "whereExist")
176+
tests.run(t)
177177
}
178178

179179
func TestWhereNotExist(t *testing.T) {
@@ -213,7 +213,7 @@ func TestWhereNotExist(t *testing.T) {
213213
{`{{whereNotExist . "Env.VIRTUAL_PROTO" | len}}`, containers, `3`},
214214
}
215215

216-
tests.run(t, "whereNotExist")
216+
tests.run(t)
217217
}
218218

219219
func TestWhereSomeMatch(t *testing.T) {
@@ -251,7 +251,7 @@ func TestWhereSomeMatch(t *testing.T) {
251251
{`{{whereAny . "Env.NOEXIST" "," (split "demo3.localhost" ",") | len}}`, containers, `0`},
252252
}
253253

254-
tests.run(t, "whereAny")
254+
tests.run(t)
255255
}
256256

257257
func TestWhereRequires(t *testing.T) {
@@ -289,7 +289,7 @@ func TestWhereRequires(t *testing.T) {
289289
{`{{whereAll . "Env.NOEXIST" "," (split "demo3.localhost" ",") | len}}`, containers, `0`},
290290
}
291291

292-
tests.run(t, "whereAll")
292+
tests.run(t)
293293
}
294294

295295
func TestWhereLabelExists(t *testing.T) {
@@ -315,7 +315,7 @@ func TestWhereLabelExists(t *testing.T) {
315315
{`{{whereLabelExists . "com.example.baz" | len}}`, containers, `0`},
316316
}
317317

318-
tests.run(t, "whereLabelExists")
318+
tests.run(t)
319319
}
320320

321321
func TestWhereLabelDoesNotExist(t *testing.T) {
@@ -341,7 +341,7 @@ func TestWhereLabelDoesNotExist(t *testing.T) {
341341
{`{{whereLabelDoesNotExist . "com.example.baz" | len}}`, containers, `2`},
342342
}
343343

344-
tests.run(t, "whereLabelDoesNotExist")
344+
tests.run(t)
345345
}
346346

347347
func TestWhereLabelValueMatches(t *testing.T) {
@@ -370,5 +370,5 @@ func TestWhereLabelValueMatches(t *testing.T) {
370370
{`{{whereLabelValueMatches . "com.example.baz" ".*" | len}}`, containers, `0`},
371371
}
372372

373-
tests.run(t, "whereLabelValueMatches")
373+
tests.run(t)
374374
}

0 commit comments

Comments
 (0)