-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_test.go
132 lines (126 loc) · 2.3 KB
/
schema_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package registry
import (
"testing"
"github.com/google/go-cmp/cmp"
)
// Set desired result.
var exampleSchema Schema = Schema{
Name: "minecraft_java",
Image: "itzg/minecraft-server:latest",
URL: "https://github.com/itzg/docker-minecraft-server",
Ratio: "1-2",
Sizes: map[string]Size{
"xs": {
Resources: Resources{
CPU: "1000m",
Memory: "2000Mi",
},
Players: 8,
},
"s": {
Resources: Resources{
CPU: "1500m",
Memory: "4000Mi",
},
Players: 16,
},
"m": {
Resources: Resources{
CPU: "2000m",
Memory: "8000Mi",
},
Players: 32,
},
"l": {
Resources: Resources{
CPU: "3000m",
Memory: "16000Mi",
},
Players: 64,
},
"xl": {
Resources: Resources{
CPU: "4000m",
Memory: "32000Mi",
},
Players: 128,
},
},
Network: []Network{
{
Name: "game",
Port: 25565,
Protocol: "tcp",
},
},
Settings: []Setting{
{
Name: "EULA",
Value: "TRUE",
},
{
Name: "VERSION",
Value: "{{ .version }}",
},
{
Name: "TYPE",
Value: "{{ .modLoader }}",
},
{
Name: "MAX_PLAYERS",
Value: "{{ .players }}",
},
{
Name: "MOTD",
Value: "{{ .name }}",
},
},
Volumes: []Volume{
{
Name: "data",
Path: "/data",
Size: "10Gi",
},
},
Probes: Probes{
Command: []string{"mc-health"},
StartupProbe: Probe{
InitialDelaySeconds: 90,
FailureThreshold: 30,
PeriodSeconds: 10,
},
ReadinessProbe: Probe{
PeriodSeconds: 5,
FailureThreshold: 20,
SuccessThreshold: 3,
},
LivenessProbe: Probe{
PeriodSeconds: 5,
FailureThreshold: 20,
},
},
}
// TestGetSchema tests that GetSchema() will return the correct schema.
func TestGetSchema(t *testing.T) {
// Test matrix.
var matrix = []struct {
name string
input string
want Schema
}{
{"correct filename", "minecraft_java.yaml", exampleSchema},
{"incorrect filename", "minecraft_java", exampleSchema},
}
// Run tests.
for _, test := range matrix {
// Call the function to test.
got, err := GetSchema(test.input)
// Error if results are incorrect.
if err != nil {
t.Fatalf("GetSchema() returned an error: \n%v", err)
}
if diff := cmp.Diff(test.want, got); diff != "" {
t.Fatalf(`GetSchema() test case "%s" mistmatch (-want +got):\n%s`, test.name, diff)
}
}
}