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 02c7f3b commit fbf9f42
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/e2e/selective_ownership_override_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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 one override scoped to single existing app
_, err = kapp.RunWithOpts([]string{"deploy", "-a", newAppName, "-f", "-", "--dangerous-scope-to-fallback-allowed-namespaces", "--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 one override scoped to both existing app
kapp.RunWithOpts([]string{"deploy", "-a", newAppName, "-f", "-", "--dangerous-scope-to-fallback-allowed-namespaces", "--ownership-override-app-filter", fmt.Sprintf("%s,%s", existingAppName1, existingAppName2)},
RunOpts{StdinReader: strings.NewReader(resourcesString)})
})
}

0 comments on commit fbf9f42

Please sign in to comment.