-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_test.go
89 lines (80 loc) · 2.31 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
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
package magekubernetes
import (
"os"
"path/filepath"
"testing"
)
func TestListFilesInDir(t *testing.T) {
dir := "tests/listfiles"
want := []string{"tests/listfiles/a.yaml", "tests/listfiles/dir/b.yaml"}
out, err := listFilesInDirectory(dir)
if !testStringSliceEq(out, want) || err != nil {
t.Fatalf(`listFilesInDirectory(dir) = %q, want match for %q`, out, want)
}
}
func TestTempDir(t *testing.T) {
dir, err := tempDir()
_, staterr := os.Stat(dir)
if err != nil || staterr != nil {
t.Fatalf(`tempDir() failed. %v %v`, err, staterr)
}
}
func TestOkRenderKustomize(t *testing.T) {
out, err := renderKustomize("tests/kustomize/overlay/production")
_, staterr := os.Stat(filepath.Join(out, "apps_v1_deployment_helloworld.yaml"))
if err != nil || staterr != nil {
t.Fatalf(`renderKustomize("tests/kustomize/overlay/production") returned an error %v or %v`, err, staterr)
}
}
func TestFailRenderKustomize(t *testing.T) {
out, err := renderKustomize("tests/kustomize/fail")
if err == nil {
t.Fatalf(`renderKustomize("tests/kustomize/overlay/fail") should return an error but returned ok status %v`, out)
}
}
func TestOkRenderHelm(t *testing.T) {
appSource := &ArgoCDAppSource{
Path: "tests/helm/ok",
Helm: ArgoCDAppHelm{
ReleaseName: "test",
ValueFiles: []string{"values.yaml"},
},
}
out, err := renderHelm(*appSource)
_, staterr := os.Stat(filepath.Join(out, "ok", "templates", "deployment.yaml"))
if err != nil || staterr != nil {
t.Fatalf(`renderHelm("tests/helm/ok") returned an error %v or %v`, err, staterr)
}
}
func TestFailRenderHelm(t *testing.T) {
appSource := &ArgoCDAppSource{
Path: "tests/helm/fail",
Helm: ArgoCDAppHelm{
ReleaseName: "test",
ValueFiles: []string{"values.yaml"},
},
}
out, err := renderHelm(*appSource)
if err == nil {
t.Fatalf(`renderKustomize("tests/helm/fail") should return an error but returned ok status %v`, out)
}
}
//// TestHelloEmpty calls greetings.Hello with an empty string,
//// checking for an error.
//func TestHelloEmpty(t *testing.T) {
// msg, err := Hello("")
// if msg != "" || err == nil {
// t.Fatalf(`Hello("") = %q, %v, want "", error`, msg, err)
// }
//}
func testStringSliceEq(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}