-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_test.go
46 lines (40 loc) · 1.21 KB
/
template_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package registry
import (
"testing"
polarisv1alpha1 "github.com/RicochetStudios/polaris/apis/v1alpha1"
"github.com/google/go-cmp/cmp"
)
// exampleServerSpec defines a minimal ServerSpec for testing.
var exampleServerSpec = polarisv1alpha1.ServerSpec{
Name: "minecraft",
Size: "s",
Game: polarisv1alpha1.Game{
Version: "1.17.1",
ModLoader: "forge",
},
}
// TestTemplate tests that TemplateValue() will return the correct value.
func TestTemplate(t *testing.T) {
// Test matrix.
var matrix = []struct {
name string
input string
want string
}{
{"correct template: .name", "{{ .name }}", "minecraft"},
{"correct template: .modLoader", "{{ .modLoader }}", "forge"},
{"correct template: .players", "{{ .players }}", "16"},
{"correct template: .version", "{{ .version }}", "1.17.1"},
{"no template", "EULA", "EULA"},
{"broken template", "{{ .players", "{{ .players"},
}
// Run tests.
for _, test := range matrix {
// Call the function to test.
got := TemplateValue(test.input, exampleSchema, exampleServerSpec)
// Error if results are incorrect.
if diff := cmp.Diff(test.want, got); diff != "" {
t.Fatalf(`TemplateValue() test case "%s" mistmatch (-want +got):\n%s`, test.name, diff)
}
}
}