Skip to content

Commit

Permalink
chore: update tests to use runCmd() (#823)
Browse files Browse the repository at this point in the history
Co-authored-by: UncleGedd <42304551+UncleGedd@users.noreply.github.com>
  • Loading branch information
TristanHoladay and UncleGedd authored Aug 18, 2024
1 parent 8cd045c commit 7dd6d54
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 499 deletions.
69 changes: 35 additions & 34 deletions src/test/e2e/bundle_deploy_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package test
import (
"fmt"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -19,51 +18,52 @@ func TestPackagesFlag(t *testing.T) {
bundleDir := "src/test/bundles/03-local-and-remote"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-test-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch))

createLocal(t, bundleDir, e2e.Arch)
runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch))

cmd := strings.Split("zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'", " ")
cmd := "zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'"
t.Run("Test only podinfo deploy (local pkg)", func(t *testing.T) {
deployPackagesFlag(bundlePath, "podinfo")
deployments, _, _ := e2e.UDS(cmd...)
runCmd(t, fmt.Sprintf("deploy %s --confirm -l=debug --packages %s", bundlePath, "podinfo"))
deployments, _ := runCmd(t, cmd)
require.Contains(t, deployments, "podinfo")
require.NotContains(t, deployments, "nginx")

remove(t, bundlePath)
deployments, _, _ = e2e.UDS(cmd...)
runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath))

deployments, _ = runCmd(t, cmd)
require.NotContains(t, deployments, "podinfo")
})

t.Run("Test only nginx deploy and remove (remote pkg)", func(t *testing.T) {
deployPackagesFlag(bundlePath, "nginx")
deployments, _, _ := e2e.UDS(cmd...)
runCmd(t, fmt.Sprintf("deploy %s --confirm -l=debug --packages %s", bundlePath, "nginx"))
deployments, _ := runCmd(t, cmd)

require.Contains(t, deployments, "nginx")
require.NotContains(t, deployments, "podinfo")
remove(t, bundlePath)

removePackagesFlag(bundlePath, "nginx")
deployments, _, _ = e2e.UDS(cmd...)
runCmd(t, fmt.Sprintf("remove %s --confirm --insecure --packages %s", bundlePath, "nginx"))
deployments, _ = runCmd(t, cmd)
require.NotContains(t, deployments, "nginx")
})

t.Run("Test both podinfo and nginx deploy and remove", func(t *testing.T) {
deployPackagesFlag(bundlePath, "podinfo,nginx")
deployments, _, _ := e2e.UDS(cmd...)
runCmd(t, fmt.Sprintf("deploy %s --confirm -l=debug --packages %s", bundlePath, "podinfo,nginx"))
deployments, _ := runCmd(t, cmd)
require.Contains(t, deployments, "podinfo")
require.Contains(t, deployments, "nginx")

removePackagesFlag(bundlePath, "podinfo,nginx")
deployments, _, _ = e2e.UDS(cmd...)
runCmd(t, fmt.Sprintf("remove %s --confirm --insecure --packages %s", bundlePath, "podinfo,nginx"))
deployments, _ = runCmd(t, cmd)
require.NotContains(t, deployments, "podinfo")
require.NotContains(t, deployments, "nginx")
})

t.Run("Test invalid package deploy", func(t *testing.T) {
_, stderr := deployPackagesFlag(bundlePath, "podinfo,nginx,peanuts")
_, stderr, _ := runCmdWithErr(fmt.Sprintf("deploy %s --confirm -l=debug --packages %s", bundlePath, "podinfo,nginx,peanuts"))
require.Contains(t, stderr, "invalid zarf packages specified by --packages")
})

t.Run("Test invalid package remove", func(t *testing.T) {
_, stderr := removePackagesFlag(bundlePath, "podinfo,nginx,peanuts")
_, stderr, _ := runCmdWithErr(fmt.Sprintf("remove %s --confirm --insecure --packages %s", bundlePath, "podinfo,nginx,peanuts"))
require.Contains(t, stderr, "invalid zarf packages specified by --packages")
})
}
Expand All @@ -74,51 +74,52 @@ func TestResumeFlag(t *testing.T) {
bundleDir := "src/test/bundles/03-local-and-remote"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-test-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch))

createLocal(t, bundleDir, e2e.Arch)
runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch))

inspectLocal(t, bundlePath)
inspectLocalAndSBOMExtract(t, bundlePath)

getDeploymentsCmd := strings.Split("zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'", " ")
getDeploymentsCmd := "zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'"

// Deploy only podinfo (local pkg)
deployPackagesFlag(bundlePath, "podinfo")
deployments, _, _ := e2e.UDS(getDeploymentsCmd...)
runCmd(t, fmt.Sprintf("deploy %s --confirm -l=debug --packages %s", bundlePath, "podinfo"))
deployments, _ := runCmd(t, getDeploymentsCmd)
require.Contains(t, deployments, "podinfo")
require.NotContains(t, deployments, "nginx")

// Deploy bundle --resume (resumes remote pkg)
deployResumeFlag(t, bundlePath)
deployments, _, _ = e2e.UDS(getDeploymentsCmd...)
runCmd(t, fmt.Sprintf("deploy %s --confirm -l=debug --resume", bundlePath))
deployments, _ = runCmd(t, getDeploymentsCmd)
require.Contains(t, deployments, "podinfo")
require.Contains(t, deployments, "nginx")

// Remove only podinfo
removePackagesFlag(bundlePath, "podinfo")
deployments, _, _ = e2e.UDS(getDeploymentsCmd...)
runCmd(t, fmt.Sprintf("remove %s --confirm --insecure --packages %s", bundlePath, "podinfo"))
deployments, _ = runCmd(t, getDeploymentsCmd)
require.NotContains(t, deployments, "podinfo")
require.Contains(t, deployments, "nginx")

// Deploy only nginx (remote pkg)
deployPackagesFlag(bundlePath, "nginx")
deployments, _, _ = e2e.UDS(getDeploymentsCmd...)
runCmd(t, fmt.Sprintf("deploy %s --confirm -l=debug --packages %s", bundlePath, "nginx"))
deployments, _ = runCmd(t, getDeploymentsCmd)
require.Contains(t, deployments, "nginx")
require.NotContains(t, deployments, "podinfo")

// Deploy bundle --resume (resumes remote pkg)
deployResumeFlag(t, bundlePath)
deployments, _, _ = e2e.UDS(getDeploymentsCmd...)
runCmd(t, fmt.Sprintf("deploy %s --confirm -l=debug --resume", bundlePath))
deployments, _ = runCmd(t, getDeploymentsCmd)
require.Contains(t, deployments, "podinfo")
require.Contains(t, deployments, "nginx")

// Remove only nginx
removePackagesFlag(bundlePath, "nginx")
deployments, _, _ = e2e.UDS(getDeploymentsCmd...)
runCmd(t, fmt.Sprintf("remove %s --confirm --insecure --packages %s", bundlePath, "nginx"))
deployments, _ = runCmd(t, getDeploymentsCmd)
require.NotContains(t, deployments, "nginx")
require.Contains(t, deployments, "podinfo")

// Remove bundle
remove(t, bundlePath)
deployments, _, _ = e2e.UDS(getDeploymentsCmd...)
runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath))
deployments, _ = runCmd(t, getDeploymentsCmd)
require.NotContains(t, deployments, "podinfo")
require.NotContains(t, deployments, "nginx")
}
21 changes: 12 additions & 9 deletions src/test/e2e/bundle_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ func TestBundleIndexInRemoteOnPublish(t *testing.T) {
tarballPath := filepath.Join("build", bundleTarballName)

// create and push bundles with different archs to the same OCI repo
createLocal(t, bundleDir, "arm64")
createLocal(t, bundleDir, "amd64")
publishInsecure(t, bundlePathARM, "localhost:888")
publishInsecure(t, bundlePathAMD, "localhost:888")
runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, "arm64"))
runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, "amd64"))

runCmd(t, fmt.Sprintf("publish %s %s --insecure", bundlePathARM, "localhost:888"))
runCmd(t, fmt.Sprintf("publish %s %s --insecure", bundlePathAMD, "localhost:888"))

// curl OCI registry for index
index, err := queryIndex(t, "http://localhost:888", bundleName)
Expand All @@ -40,7 +41,8 @@ func TestBundleIndexInRemoteOnPublish(t *testing.T) {
deployAndRemoveLocalAndRemoteInsecure(t, fmt.Sprintf("oci://localhost:888/%s:0.0.1", bundleName), tarballPath)

// now test by running 'create -o' over the bundle that was published
createRemoteInsecure(t, bundleDir, "oci://localhost:888", e2e.Arch)
runCmd(t, fmt.Sprintf("create %s -o %s --confirm --insecure -a %s", bundleDir, "oci://localhost:888", e2e.Arch))

index, err = queryIndex(t, "http://localhost:888", bundleName)
require.NoError(t, err)
ValidateMultiArchIndex(t, index)
Expand All @@ -60,8 +62,8 @@ func TestBundleIndexInRemoteOnCreate(t *testing.T) {
tarballPath := filepath.Join("build", bundleTarballName)

// create and push bundles with different archs to the same OCI repo
createRemoteInsecure(t, bundleDir, "oci://localhost:888", "arm64")
createRemoteInsecure(t, bundleDir, "oci://localhost:888", "amd64")
runCmd(t, fmt.Sprintf("create %s -o %s --confirm --insecure -a %s", bundleDir, "oci://localhost:888", "arm64"))
runCmd(t, fmt.Sprintf("create %s -o %s --confirm --insecure -a %s", bundleDir, "oci://localhost:888", "amd64"))

// curl OCI registry for index
index, err := queryIndex(t, "http://localhost:888", bundleName)
Expand All @@ -73,8 +75,9 @@ func TestBundleIndexInRemoteOnCreate(t *testing.T) {
deployAndRemoveLocalAndRemoteInsecure(t, fmt.Sprintf("oci://localhost:888/%s:0.0.1", bundleName), tarballPath)

// now test by publishing over the bundle that was created with 'create -o'
createLocal(t, bundleDir, e2e.Arch)
publishInsecure(t, tarballPath, "localhost:888")
runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch))
runCmd(t, fmt.Sprintf("publish %s %s --insecure", tarballPath, "localhost:888"))

index, err = queryIndex(t, "http://localhost:888", bundleName)
require.NoError(t, err)
ValidateMultiArchIndex(t, index)
Expand Down
Loading

0 comments on commit 7dd6d54

Please sign in to comment.