-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_test.go
78 lines (64 loc) · 1.79 KB
/
render_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
package main
import (
"fmt"
"html/template"
"io/ioutil"
"testing"
"github.com/Masterminds/sprig"
"k8s.io/client-go/kubernetes/fake"
)
func runRenderFor(router string) (actual string, expected string) {
rules := generateRules("./examples/ingressList.json")
client := fake.NewSimpleClientset(&rules)
irules, err := ScrapeIngresses(client, "")
if err != nil {
panic(err)
}
config := ReadConfig(fmt.Sprintf("./examples/config_for_%s.yaml", router))
fmap := template.FuncMap{
"GroupByHost": GroupByHost,
"GroupByPath": GroupByPath,
}
tmpl, err := PrepareTemplate(config.InTemplate, BuildFuncMap(fmap, sprig.FuncMap()))
if err != nil {
panic(err)
}
cxt := ICxt{IngRules: ToIngressifyRule(irules)}
err = RenderTemplate(tmpl, config.OutTemplate, cxt)
if err != nil {
panic(err)
}
actualRes, err := ioutil.ReadFile(fmt.Sprintf("/tmp/%s.actual", router))
if err != nil {
panic(err)
}
expectedRes, err := ioutil.ReadFile(fmt.Sprintf("./examples/%s.expected", router))
if err != nil {
panic(err)
}
actual = string(actualRes)
expected = string(expectedRes)
return
}
func TestRenderNginxTemplate(t *testing.T) {
nginxActual, nginxExpected := runRenderFor("nginx")
if string(nginxActual) != string(nginxExpected) {
t.Errorf("Template results differ")
fmt.Println("Expected:")
fmt.Printf("%s\n", nginxExpected)
fmt.Println("----------------------")
fmt.Println("Got: ")
fmt.Printf("%s\n", nginxActual)
}
}
func TestRenderHaproxyTemplate(t *testing.T) {
haproxyActual, haproxyExpected := runRenderFor("haproxy")
if string(haproxyActual) != string(haproxyExpected) {
t.Errorf("Template results differ")
fmt.Println("Expected:")
fmt.Printf("%s\n", haproxyExpected)
fmt.Println("----------------------")
fmt.Println("Got: ")
fmt.Printf("%s\n", haproxyActual)
}
}