This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain_test.go
77 lines (70 loc) · 2.34 KB
/
main_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
package main
import (
"bytes"
"os"
"path"
"testing"
"github.com/stretchr/testify/require"
)
func TestCLI(t *testing.T) {
tests := []struct {
summary string
fromFile string
toFile string
outputFile string
ignored string
expectedOutput string
}{
{
summary: "same manifest",
fromFile: path.Join("testdata", "kyma-1.yaml"),
toFile: path.Join("testdata", "kyma-1.yaml"),
outputFile: path.Join("testdata", "test-result.sh"),
},
{
summary: "two orphans after upgrade",
fromFile: path.Join("testdata", "kyma-1.yaml"),
toFile: path.Join("testdata", "kyma-2.yaml"),
outputFile: path.Join("testdata", "test-result.sh"),
expectedOutput: `#!/usr/bin/env bash
kubectl delete -n kyma-system authorizationpolicies.security.istio.io tracing-jaeger
kubectl delete -n kyma-system clusterrolebindings.rbac.authorization.k8s.io cluster-essentials-pod-preset-webhook
kubectl delete -n kyma-system configmaps tracing-grafana-dashboard
kubectl delete -n kyma-system podsecuritypolicies.policy 002-kyma-privileged
kubectl delete -n kyma-system servicemonitors.monitoring.coreos.com tracing-jaeger-operator
`,
},
{
summary: "one orphans after upgrade with ignored",
fromFile: path.Join("testdata", "kyma-1.yaml"),
toFile: path.Join("testdata", "kyma-2.yaml"),
outputFile: path.Join("testdata", "test-result.sh"),
ignored: "servicemonitor.monitoring.coreos.com:tracing-jaeger-operator,configmap:tracing-grafana-dashboard",
expectedOutput: `#!/usr/bin/env bash
kubectl delete -n kyma-system authorizationpolicies.security.istio.io tracing-jaeger
kubectl delete -n kyma-system clusterrolebindings.rbac.authorization.k8s.io cluster-essentials-pod-preset-webhook
kubectl delete -n kyma-system podsecuritypolicies.policy 002-kyma-privileged
`,
},
}
for _, tc := range tests {
t.Run(tc.summary, func(t *testing.T) {
buf := bytes.NewBufferString("")
err := run(buf, flags{
fromFile: tc.fromFile,
toFile: tc.toFile,
ignored: tc.ignored,
outputFile: tc.outputFile,
})
defer os.Remove(tc.outputFile)
require.NoError(t, err)
content, err := os.ReadFile(tc.outputFile)
if tc.expectedOutput != "" {
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, string(content))
} else {
require.Error(t, err)
}
})
}
}