Skip to content

Commit 012a5ae

Browse files
committed
Add tests for custom template functions
1 parent 748a621 commit 012a5ae

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

template_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestContains(t *testing.T) {
8+
env := map[string]string{
9+
"PORT": "1234",
10+
}
11+
12+
if !contains(env, "PORT") {
13+
t.Fail()
14+
}
15+
16+
if contains(env, "MISSING") {
17+
t.Fail()
18+
}
19+
}
20+
21+
func TestGroupByExitingKey(t *testing.T) {
22+
containers := []*RuntimeContainer{
23+
&RuntimeContainer{
24+
Env: map[string]string{
25+
"VIRTUAL_HOST": "demo1.localhost",
26+
},
27+
ID: "1",
28+
},
29+
&RuntimeContainer{
30+
Env: map[string]string{
31+
"VIRTUAL_HOST": "demo1.localhost",
32+
},
33+
ID: "2",
34+
},
35+
&RuntimeContainer{
36+
Env: map[string]string{
37+
"VIRTUAL_HOST": "demo2.localhost",
38+
},
39+
ID: "3",
40+
},
41+
}
42+
43+
groups := groupBy(containers, "Env.VIRTUAL_HOST")
44+
if len(groups) != 2 {
45+
t.Fail()
46+
}
47+
48+
if len(groups["demo1.localhost"]) != 2 {
49+
t.Fail()
50+
}
51+
52+
if len(groups["demo2.localhost"]) != 1 {
53+
t.Fail()
54+
}
55+
if groups["demo2.localhost"][0].ID != "3" {
56+
t.Fail()
57+
}
58+
}

0 commit comments

Comments
 (0)