forked from carvel-dev/kapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_metadata_output_test.go
96 lines (77 loc) · 2.82 KB
/
app_metadata_output_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
90
91
92
93
94
95
96
// Copyright 2020 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package e2e
import (
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)
func TestAppKindChangeWithMetadataOutput(t *testing.T) {
env := BuildEnv(t)
logger := Logger{}
kapp := Kapp{t, env.Namespace, env.KappBinaryPath, logger}
yaml1 := `
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-config
annotations:
kapp.k14s.io/versioned: ""
data:
redis-config: |
maxmemory 3mb
maxmemory-policy allkeys-lru
`
yaml2 := `
---
apiVersion: v1
kind: Secret
metadata:
name: kapp-secret-1
namespace: kapp-namespace-2
`
name := "test-app-change"
cleanUp := func() {
kapp.Run([]string{"delete", "-a", name})
}
cleanUp()
defer cleanUp()
firstDeploy, err := os.CreateTemp(os.TempDir(), "output1")
assert.NoError(t, err)
secondDeploy, err := os.CreateTemp(os.TempDir(), "output2")
assert.NoError(t, err)
thirdDeploy, err := os.CreateTemp(os.TempDir(), "output3")
assert.NoError(t, err)
defer func() {
os.Remove(firstDeploy.Name())
os.Remove(secondDeploy.Name())
}()
logger.Section("deploy app", func() {
kapp.RunWithOpts([]string{"deploy", "--app-metadata-file-output", firstDeploy.Name(), "-f", "-", "-a", name}, RunOpts{IntoNs: true, StdinReader: strings.NewReader(yaml1)})
})
logger.Section("deploy with changes", func() {
kapp.RunWithOpts([]string{"deploy", "--app-metadata-file-output", secondDeploy.Name(), "-f", "-", "-a", name}, RunOpts{IntoNs: true, StdinReader: strings.NewReader(yaml2)})
})
logger.Section("deploy with no changes", func() {
kapp.RunWithOpts([]string{"deploy", "--app-metadata-file-output", thirdDeploy.Name(), "-f", "-", "-a", name}, RunOpts{IntoNs: true, StdinReader: strings.NewReader(yaml2)})
})
configMapFirstDeploy, err := os.ReadFile(firstDeploy.Name())
assert.NoError(t, err)
firstConfigMap := yamlSubset{}
require.NoError(t, yaml.Unmarshal(configMapFirstDeploy, &firstConfigMap))
require.Equal(t, yamlSubset{LastChange: lastChange{Namespaces: []string{env.Namespace}}, UsedGKs: []usedGK{{Group: "", Kind: "ConfigMap"}}}, firstConfigMap)
configMapSecondDeploy, err := os.ReadFile(secondDeploy.Name())
assert.NoError(t, err)
secondConfigMap := yamlSubset{}
require.NoError(t, yaml.Unmarshal(configMapSecondDeploy, &secondConfigMap))
require.Equal(t, yamlSubset{LastChange: lastChange{Namespaces: []string{env.Namespace}}, UsedGKs: []usedGK{{Group: "", Kind: "Secret"}}}, secondConfigMap)
configMapThirdDeploy, err := os.ReadFile(thirdDeploy.Name())
assert.NoError(t, err)
thirdConfigMap := yamlSubset{}
require.NoError(t, yaml.Unmarshal(configMapThirdDeploy, &thirdConfigMap))
require.Equal(t, yamlSubset{LastChange: lastChange{Namespaces: []string{env.Namespace}}, UsedGKs: []usedGK{{Group: "", Kind: "Secret"}}}, thirdConfigMap)
}