1 package cmd
2
3 import (
4 "bytes"
5 "fmt"
6 "testing"
7
8 charts "github.com/linkerd/linkerd2/pkg/charts"
9 )
10
11 func TestRender(t *testing.T) {
12
13
14 defaultValues := map[string]interface{}{
15 "tap": map[string]interface{}{
16 "externalSecret": true,
17 "caBundle": "test-tap-ca-bundle",
18 },
19 "tapInjector": map[string]interface{}{
20 "externalSecret": true,
21 "caBundle": "test-tap-ca-bundle",
22 },
23 }
24
25 proxyResources := map[string]interface{}{
26 "proxy": map[string]interface{}{
27 "resources": map[string]interface{}{
28 "cpu": map[string]interface{}{
29 "request": "500m",
30 "limit": "100m",
31 },
32 "memory": map[string]interface{}{
33 "request": "20Mi",
34 "limit": "250Mi",
35 },
36 },
37 },
38 }
39
40 testCases := []struct {
41 values map[string]interface{}
42 goldenFileName string
43 }{
44 {
45 nil,
46 "install_default.golden",
47 },
48 {
49 map[string]interface{}{
50 "prometheus": map[string]interface{}{
51 "args": map[string]interface{}{
52 "log.level": "debug",
53 }},
54 },
55 "install_prometheus_loglevel_from_args.golden",
56 },
57 {
58 map[string]interface{}{
59 "prometheus": map[string]interface{}{"enabled": false},
60 "prometheusUrl": "external-prom.com",
61 },
62 "install_prometheus_disabled.golden",
63 },
64 {
65 map[string]interface{}{
66 "prometheus": proxyResources,
67 "tap": proxyResources,
68 "dashboard": proxyResources,
69 },
70 "install_proxy_resources.golden",
71 },
72 {
73 map[string]interface{}{
74 "defaultLogLevel": "debug",
75 "defaultUID": 1234,
76 "defaultGID": 1234,
77 "defaultRegistry": "gcr.io/linkerd",
78 "tap": map[string]interface{}{
79 "logLevel": "info",
80 "UID": 5678,
81 "GID": 5678,
82 "image": map[string]interface{}{
83 "registry": "cr.l5d.io/linkerd",
84 "tag": "stable-9.2",
85 },
86 },
87 "grafana": map[string]interface{}{"url": "grafana.grafana:3000"},
88 },
89 "install_default_overrides.golden",
90 },
91 }
92
93 for i, tc := range testCases {
94 tc := tc
95 t.Run(fmt.Sprintf("%d: %s", i, tc.goldenFileName), func(t *testing.T) {
96 var buf bytes.Buffer
97
98 if err := render(&buf, charts.MergeMaps(defaultValues, tc.values)); err != nil {
99 t.Fatalf("Failed to render templates: %v", err)
100 }
101 if err := testDataDiffer.DiffTestYAML(tc.goldenFileName, buf.String()); err != nil {
102 t.Error(err)
103 }
104 })
105 }
106 }
107
View as plain text