Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved TestAppKindChangeWithMetadataOutput to a separate file #880

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions test/e2e/app_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ package e2e

import (
"fmt"
"os"
"strings"
"testing"
"time"

uitest "github.com/cppforlife/go-cli-ui/ui/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/carvel-kapp/pkg/kapp/app"
"gopkg.in/yaml.v2"
)

func TestAppChange(t *testing.T) {
Expand Down Expand Up @@ -141,88 +138,6 @@ spec:
})
}

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)
}

func TestAppChangesMaxToKeep(t *testing.T) {
env := BuildEnv(t)
logger := Logger{}
Expand Down
96 changes: 96 additions & 0 deletions test/e2e/app_metadata_output_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}
Loading