Skip to content

Commit

Permalink
Add tests for selective ownership override
Browse files Browse the repository at this point in the history
Signed-off-by: Soumik Majumder <[email protected]>
  • Loading branch information
100mik committed Aug 5, 2024
1 parent f0a6a5e commit 24a56f5
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/e2e/selective_ownership_override_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0

package e2e

import (
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestSelectiveOwnershipOverride(t *testing.T) {
env := BuildEnv(t)
logger := Logger{}
kapp := Kapp{t, env.Namespace, env.KappBinaryPath, logger}

const existingAppName1 = "existing-app-1"
const existingAppName2 = "existing-app-2"
const newAppName = "new-app"

resourceYAML := `
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cm-%s
data:
foo: bar
`

cleanUp := func() {
kapp.Run([]string{"delete", "-a", existingAppName1})
kapp.Run([]string{"delete", "-a", existingAppName2})
kapp.Run([]string{"delete", "-a", newAppName})
}
cleanUp()
defer cleanUp()

logger.Section("deploy existing apps", func() {
kapp.RunWithOpts([]string{"deploy", "-a", existingAppName1, "-f", "-"}, RunOpts{StdinReader: strings.NewReader(fmt.Sprintf(resourceYAML, "1"))})
kapp.RunWithOpts([]string{"deploy", "-a", existingAppName2, "-f", "-"}, RunOpts{StdinReader: strings.NewReader(fmt.Sprintf(resourceYAML, "2"))})
})

logger.Section("deploy new app with selective overrides", func() {
resourcesString := fmt.Sprintf("%s%s", fmt.Sprintf(resourceYAML, "1"), fmt.Sprintf(resourceYAML, "2"))
// Overrides disallowed
_, err := kapp.RunWithOpts([]string{"deploy", "-a", newAppName, "-f", "-"}, RunOpts{StdinReader: strings.NewReader(resourcesString), AllowError: true})
require.Error(t, err)
require.Contains(t, err.Error(), existingAppName1)
require.Contains(t, err.Error(), existingAppName2)

// Test with override scoped while override is disallowed
_, err = kapp.RunWithOpts([]string{"deploy", "-a", newAppName, "-f", "-", "--ownership-override-app-filter", existingAppName1},
RunOpts{StdinReader: strings.NewReader(resourcesString), AllowError: true})
require.Error(t, err)
require.Contains(t, err.Error(), existingAppName1)
require.Contains(t, err.Error(), existingAppName2)

// Test with override scoped to single existing app
_, err = kapp.RunWithOpts([]string{"deploy", "-a", newAppName, "-f", "-", "--dangerous-override-ownership-of-existing-resources", "--ownership-override-app-filter", existingAppName1},
RunOpts{StdinReader: strings.NewReader(resourcesString), AllowError: true})
require.Error(t, err)
require.NotContains(t, err.Error(), existingAppName1)
require.Contains(t, err.Error(), existingAppName2)

// Test with override scoped to both existing app
kapp.RunWithOpts([]string{"deploy", "-a", newAppName, "-f", "-", "--dangerous-override-ownership-of-existing-resources", "--ownership-override-app-filter", fmt.Sprintf("%s,%s", existingAppName1, existingAppName2)},
RunOpts{StdinReader: strings.NewReader(resourcesString)})
})
}

0 comments on commit 24a56f5

Please sign in to comment.