From 7dd6d549d8724ff40410600d493c917e9336ffd9 Mon Sep 17 00:00:00 2001 From: Tristan Holaday <40547442+TristanHoladay@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:25:00 -0600 Subject: [PATCH] chore: update tests to use runCmd() (#823) Co-authored-by: UncleGedd <42304551+UncleGedd@users.noreply.github.com> --- src/test/e2e/bundle_deploy_flags_test.go | 69 ++++----- src/test/e2e/bundle_index_test.go | 21 +-- src/test/e2e/bundle_test.go | 158 +++++++++------------ src/test/e2e/commands_test.go | 170 +++-------------------- src/test/e2e/completion_test.go | 13 +- src/test/e2e/dev_test.go | 82 ++++------- src/test/e2e/ghcr_test.go | 24 ++-- src/test/e2e/main_test.go | 14 +- src/test/e2e/monitor_test.go | 12 +- src/test/e2e/optional_bundle_test.go | 14 +- src/test/e2e/security_hub_test.go | 4 +- src/test/e2e/variable_test.go | 160 +++++++-------------- src/test/e2e/zarf_test.go | 12 +- tasks/tests.yaml | 2 +- 14 files changed, 256 insertions(+), 499 deletions(-) diff --git a/src/test/e2e/bundle_deploy_flags_test.go b/src/test/e2e/bundle_deploy_flags_test.go index 1146842b..437d8d91 100644 --- a/src/test/e2e/bundle_deploy_flags_test.go +++ b/src/test/e2e/bundle_deploy_flags_test.go @@ -7,7 +7,6 @@ package test import ( "fmt" "path/filepath" - "strings" "testing" "github.com/stretchr/testify/require" @@ -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") }) } @@ -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") } diff --git a/src/test/e2e/bundle_index_test.go b/src/test/e2e/bundle_index_test.go index 8fdc3694..652f3ec8 100644 --- a/src/test/e2e/bundle_index_test.go +++ b/src/test/e2e/bundle_index_test.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/src/test/e2e/bundle_test.go b/src/test/e2e/bundle_test.go index 51f06703..56e049eb 100644 --- a/src/test/e2e/bundle_test.go +++ b/src/test/e2e/bundle_test.go @@ -29,9 +29,8 @@ func TestUDSCmd(t *testing.T) { func TestUDSLogs(t *testing.T) { zarfPkgPath := "src/test/packages/no-cluster/real-simple" e2e.CreateZarfPkg(t, zarfPkgPath, false) - createLocal(t, "src/test/bundles/11-real-simple", e2e.Arch) - stdout, _, err := e2e.UDS("logs") - require.NoError(t, err) + runCmd(t, fmt.Sprintf("create src/test/bundles/11-real-simple --insecure --confirm -a %s", e2e.Arch)) + stdout, _ := runCmd(t, "logs") require.Contains(t, stdout, "DEBUG") require.Contains(t, stdout, "UDSBundle") } @@ -41,8 +40,9 @@ func TestSimpleBundleWithZarfAction(t *testing.T) { e2e.CreateZarfPkg(t, zarfPkgPath, false) os.Setenv("UDS_LOG_LEVEL", "debug") defer os.Unsetenv("UDS_LOG_LEVEL") - createLocal(t, "src/test/bundles/11-real-simple", e2e.Arch) - _, stderr := deploy(t, fmt.Sprintf("src/test/bundles/11-real-simple/uds-bundle-real-simple-%s-0.0.1.tar.zst", e2e.Arch)) + runCmd(t, fmt.Sprintf("create src/test/bundles/11-real-simple --insecure --confirm -a %s", e2e.Arch)) + tarballPath := fmt.Sprintf("src/test/bundles/11-real-simple/uds-bundle-real-simple-%s-0.0.1.tar.zst", e2e.Arch) + _, stderr := runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", tarballPath)) require.Contains(t, stderr, "Log level set to debug") } @@ -54,7 +54,8 @@ func TestSimpleBundleWithNameAndVersionFlags(t *testing.T) { name, version := "name-from-flag", "version-from-flag" bundlePath := "src/test/bundles/11-real-simple" runCmd(t, fmt.Sprintf("create %s --confirm --name %s --version %s", bundlePath, name, version)) - _, stderr := deploy(t, fmt.Sprintf("src/test/bundles/11-real-simple/uds-bundle-%s-%s-%s.tar.zst", name, e2e.Arch, version)) + tarballPath := fmt.Sprintf("src/test/bundles/11-real-simple/uds-bundle-%s-%s-%s.tar.zst", name, e2e.Arch, version) + _, stderr := runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", tarballPath)) require.Contains(t, stderr, "Log level set to debug") } @@ -69,10 +70,10 @@ func TestCreateWithNoPath(t *testing.T) { defer e2e.TeardownRegistry(t, 888) pkg := filepath.Join(zarfPkgPath1, fmt.Sprintf("zarf-package-output-var-%s-0.0.1.tar.zst", e2e.Arch)) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) pkg = filepath.Join(zarfPkgPath2, fmt.Sprintf("zarf-package-receive-var-%s-0.0.1.tar.zst", e2e.Arch)) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) // move the bundle to the current directory so we can test the create command with no path err := os.Link(fmt.Sprintf("src/test/bundles/02-variables/remote/%s", config.BundleYAML), config.BundleYAML) @@ -81,9 +82,7 @@ func TestCreateWithNoPath(t *testing.T) { defer os.Remove(fmt.Sprintf("uds-bundle-variables-%s-0.0.1.tar.zst", e2e.Arch)) // create - cmd := strings.Split("create --confirm --insecure", " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, "create --confirm --insecure") } func TestBundleWithLocalAndRemotePkgs(t *testing.T) { @@ -105,23 +104,24 @@ func TestBundleWithLocalAndRemotePkgs(t *testing.T) { Repository: "test-local-and-remote", Reference: "0.0.1", } - createLocal(t, bundleDir, e2e.Arch) + + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) inspectLocal(t, bundlePath) - deploy(t, bundlePath) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) t.Run("Test pulling and deploying from the same registry", func(t *testing.T) { - publishInsecure(t, bundlePath, bundleRef.Registry) + runCmd(t, fmt.Sprintf("publish %s %s --insecure", bundlePath, bundleRef.Registry)) pull(t, bundleRef.String(), bundleTarballName) // note that pull pulls the bundle into the build dir - deploy(t, pulledBundlePath) - remove(t, pulledBundlePath) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", pulledBundlePath)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", pulledBundlePath)) }) t.Run(" Test publishing and deploying from different registries", func(t *testing.T) { - publishInsecure(t, bundlePath, bundleRef.Registry) + runCmd(t, fmt.Sprintf("publish %s %s --insecure", bundlePath, bundleRef.Registry)) pull(t, bundleRef.String(), bundleTarballName) // note that pull pulls the bundle into the build dir - publishInsecure(t, pulledBundlePath, "oci://localhost:889") - deployInsecure(t, bundleRef.String()) + runCmd(t, fmt.Sprintf("publish %s %s --insecure", pulledBundlePath, "oci://localhost:889")) + runCmd(t, fmt.Sprintf("deploy %s --insecure --confirm", bundleRef.String())) }) } @@ -137,19 +137,19 @@ func TestLocalBundleWithRemotePkgs(t *testing.T) { defer e2e.TeardownRegistry(t, 889) pkg := fmt.Sprintf("src/test/packages/nginx/zarf-package-nginx-%s-0.0.1.tar.zst", e2e.Arch) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) pkg = fmt.Sprintf("src/test/packages/podinfo/zarf-package-podinfo-%s-0.0.1.tar.zst", e2e.Arch) - zarfPublish(t, pkg, "localhost:889") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:889 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) bundleDir := "src/test/bundles/01-uds-bundle" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-example-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) - deploy(t, bundlePath) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) } func TestRemoteBundleWithRemotePkgs(t *testing.T) { @@ -163,10 +163,10 @@ func TestRemoteBundleWithRemotePkgs(t *testing.T) { defer e2e.TeardownRegistry(t, 889) pkg := fmt.Sprintf("src/test/packages/nginx/zarf-package-nginx-%s-0.0.1.tar.zst", e2e.Arch) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) pkg = fmt.Sprintf("src/test/packages/podinfo/zarf-package-podinfo-%s-0.0.1.tar.zst", e2e.Arch) - zarfPublish(t, pkg, "localhost:889") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:889 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) bundleRef := registry.Reference{ Registry: "oci://localhost:888", @@ -178,10 +178,10 @@ func TestRemoteBundleWithRemotePkgs(t *testing.T) { bundleTarballName := fmt.Sprintf("uds-bundle-example-remote-%s-0.0.1.tar.zst", e2e.Arch) tarballPath := filepath.Join("build", bundleTarballName) bundlePath := "src/test/bundles/01-uds-bundle" - createRemoteInsecure(t, bundlePath, bundleRef.Registry, e2e.Arch) + runCmd(t, fmt.Sprintf("create %s -o %s --confirm --insecure -a %s", bundlePath, bundleRef.Registry, e2e.Arch)) // Test without oci prefix - createRemoteInsecure(t, bundlePath, "localhost:888", e2e.Arch) + runCmd(t, fmt.Sprintf("create %s -o %s --confirm --insecure -a %s", bundlePath, "localhost:888", e2e.Arch)) pull(t, bundleRef.String(), bundleTarballName) inspectRemoteInsecure(t, bundleRef.String()) @@ -202,9 +202,9 @@ func TestBundleWithGitRepo(t *testing.T) { bundleDir := "src/test/bundles/05-gitrepo" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-gitrepo-%s-0.0.1.tar.zst", e2e.Arch)) - createLocal(t, bundleDir, e2e.Arch) - deploy(t, bundlePath) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) } func TestBundleWithYmlFile(t *testing.T) { @@ -214,44 +214,35 @@ func TestBundleWithYmlFile(t *testing.T) { bundleDir := "src/test/bundles/09-uds-bundle-yml" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-yml-example-%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) os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/09-uds-bundle-yml", "uds-config.yml")) defer os.Unsetenv("UDS_CONFIG") - deploy(t, bundlePath) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) } func TestLocalBundleWithOutput(t *testing.T) { path := "src/test/packages/nginx" - args := strings.Split(fmt.Sprintf("zarf package create %s -o %s --confirm", path, path), " ") - _, _, err := e2e.UDS(args...) - require.NoError(t, err) + e2e.CreateZarfPkg(t, path, false) bundleDir := "src/test/bundles/09-uds-bundle-yml" destDir := "src/test/test/" bundlePath := filepath.Join(destDir, fmt.Sprintf("uds-bundle-yml-example-%s-0.0.1.tar.zst", e2e.Arch)) - createLocalWithOuputFlag(t, bundleDir, destDir, e2e.Arch) - - cmd := strings.Split(fmt.Sprintf("inspect %s", bundlePath), " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("create %s -o %s --insecure --confirm -a %s", bundleDir, destDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("inspect %s", bundlePath)) } func TestLocalBundleWithNoSBOM(t *testing.T) { path := "src/test/packages/nginx" - args := strings.Split(fmt.Sprintf("zarf package create %s -o %s --skip-sbom --confirm", path, path), " ") - _, _, err := e2e.UDS(args...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("zarf package create %s -o %s --skip-sbom --confirm", path, path)) bundleDir := "src/test/bundles/09-uds-bundle-yml" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-yml-example-%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(fmt.Sprintf("inspect %s --sbom --extract", bundlePath), " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + stdout, _ := runCmd(t, fmt.Sprintf("inspect %s --sbom --extract", bundlePath)) require.Contains(t, stdout, "Cannot extract, no SBOMs found in bundle") require.Contains(t, stdout, "sboms.tar not found in Zarf pkg") } @@ -266,12 +257,10 @@ func TestRemoteBundleWithNoSBOM(t *testing.T) { defer e2e.TeardownRegistry(t, 888) bundleDir := "src/test/bundles/09-uds-bundle-yml" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-yml-example-%s-0.0.1.tar.zst", e2e.Arch)) - createLocal(t, bundleDir, e2e.Arch) - publishInsecure(t, bundlePath, "localhost:888") + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("publish %s %s --insecure", bundlePath, "localhost:888")) - cmd := strings.Split(fmt.Sprintf("inspect %s --sbom --extract", bundlePath), " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + stdout, _ := runCmd(t, fmt.Sprintf("inspect %s --sbom --extract", bundlePath)) require.Contains(t, stdout, "Cannot extract, no SBOMs found in bundle") require.Contains(t, stdout, "sboms.tar not found in Zarf pkg") } @@ -288,10 +277,10 @@ func TestPackageNaming(t *testing.T) { defer e2e.TeardownRegistry(t, 889) pkg := fmt.Sprintf("src/test/packages/nginx/zarf-package-nginx-%s-0.0.1.tar.zst", e2e.Arch) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) pkg = fmt.Sprintf("src/test/packages/podinfo/zarf-package-podinfo-%s-0.0.1.tar.zst", e2e.Arch) - zarfPublish(t, pkg, "localhost:889") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:889 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) bundleDir := "src/test/bundles/10-package-naming" bundleTarballName := fmt.Sprintf("uds-bundle-package-naming-%s-0.0.1.tar.zst", e2e.Arch) @@ -303,14 +292,15 @@ func TestPackageNaming(t *testing.T) { Repository: "package-naming", Reference: "0.0.1", } - createLocal(t, bundleDir, e2e.Arch) // todo: allow creating from both the folder containing and direct reference to uds-bundle.yaml - publishInsecure(t, bundlePath, bundleRef.Registry) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) // todo: allow creating from both the folder containing and direct reference to uds-bundle.yaml + runCmd(t, fmt.Sprintf("publish %s %s --insecure", bundlePath, bundleRef.Registry)) + pull(t, bundleRef.String(), bundleTarballName) - deploy(t, tarballPath) - remove(t, tarballPath) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", tarballPath)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", tarballPath)) // Test create -o with zarf package names that don't match the zarf package name in the bundle - createRemoteInsecure(t, bundleDir, bundleRef.Registry, e2e.Arch) + runCmd(t, fmt.Sprintf("create %s -o %s --confirm --insecure -a %s", bundleDir, bundleRef.Registry, e2e.Arch)) deployAndRemoveLocalAndRemoteInsecure(t, bundleRef.String(), tarballPath) } @@ -321,14 +311,14 @@ func TestBundleWithComposedPkgComponent(t *testing.T) { zarfPkgPath := "src/test/packages/prometheus" pkg := filepath.Join(zarfPkgPath, fmt.Sprintf("zarf-package-prometheus-%s-0.0.1.tar.zst", e2e.Arch)) e2e.CreateZarfPkg(t, zarfPkgPath, false) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) bundleDir := "src/test/bundles/13-composable-component" bundleName := "with-composed" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-%s-%s-0.0.1.tar.zst", bundleName, e2e.Arch)) - createLocal(t, bundleDir, e2e.Arch) - deploy(t, bundlePath) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) } func TestBundleTmpDir(t *testing.T) { @@ -425,8 +415,7 @@ func TestInvalidConfig(t *testing.T) { defer os.Unsetenv("UDS_CONFIG") zarfPkgPath := "src/test/packages/helm" e2e.HelmDepUpdate(t, fmt.Sprintf("%s/unicorn-podinfo", zarfPkgPath)) - args := strings.Split(fmt.Sprintf("zarf package create %s -o %s --confirm", zarfPkgPath, zarfPkgPath), " ") - _, stdErr, _ := e2e.UDS(args...) + _, stdErr, _ := runCmdWithErr(fmt.Sprintf("zarf package create %s -o %s --confirm", zarfPkgPath, zarfPkgPath)) count := strings.Count(stdErr, "invalid config option: log_levelx") require.Equal(t, 1, count, "The string 'invalid config option: log_levelx' should appear exactly once") require.NotContains(t, stdErr, "Usage:") @@ -438,7 +427,7 @@ func TestInvalidBundle(t *testing.T) { e2e.HelmDepUpdate(t, fmt.Sprintf("%s/unicorn-podinfo", zarfPkgPath)) e2e.CreateZarfPkg(t, zarfPkgPath, false) bundleDir := "src/test/bundles/07-helm-overrides/invalid" - stderr := createLocalError(bundleDir, e2e.Arch) + _, stderr, _ := runCmdWithErr(fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) require.Contains(t, stderr, "unknown field") } @@ -455,9 +444,9 @@ func TestArchCheck(t *testing.T) { e2e.CreateZarfPkgWithArch(t, zarfPkgPath, false, testArch) bundleDir := "src/test/bundles/07-helm-overrides" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-helm-overrides-%s-0.0.1.tar.zst", testArch)) - createLocal(t, bundleDir, testArch) - cmd := strings.Split(fmt.Sprintf("deploy %s --confirm", bundlePath), " ") - _, stderr, _ := e2e.UDS(cmd...) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, testArch)) + + _, stderr, _ := runCmdWithErr(fmt.Sprintf("deploy %s --confirm", bundlePath)) require.Contains(t, stderr, fmt.Sprintf("arch %s does not match cluster arch, [%s]", testArch, e2e.Arch)) } @@ -468,7 +457,7 @@ func TestListImages(t *testing.T) { zarfPkgPath := "src/test/packages/prometheus" pkg := filepath.Join(zarfPkgPath, fmt.Sprintf("zarf-package-prometheus-%s-0.0.1.tar.zst", e2e.Arch)) e2e.CreateZarfPkg(t, zarfPkgPath, false) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) zarfPkgPath = "src/test/packages/podinfo-nginx" e2e.CreateZarfPkg(t, zarfPkgPath, false) @@ -476,9 +465,7 @@ func TestListImages(t *testing.T) { bundleDir := "src/test/bundles/14-optional-components" t.Run("list images on bundle YAML only", func(t *testing.T) { - cmd := strings.Split(fmt.Sprintf("inspect %s --list-images --insecure", filepath.Join(bundleDir, config.BundleYAML)), " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + stdout, _ := runCmd(t, fmt.Sprintf("inspect %s --list-images --insecure", filepath.Join(bundleDir, config.BundleYAML))) require.Contains(t, stdout, "library/registry") require.Contains(t, stdout, "ghcr.io/zarf-dev/zarf/agent") require.Contains(t, stdout, "nginx") @@ -522,7 +509,7 @@ func TestListVariables(t *testing.T) { zarfPkgPath := "src/test/packages/prometheus" pkg := filepath.Join(zarfPkgPath, fmt.Sprintf("zarf-package-prometheus-%s-0.0.1.tar.zst", e2e.Arch)) e2e.CreateZarfPkg(t, zarfPkgPath, false) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) zarfPkgPath = "src/test/packages/podinfo-nginx" e2e.CreateZarfPkg(t, zarfPkgPath, false) @@ -530,28 +517,21 @@ func TestListVariables(t *testing.T) { bundleDir := "src/test/bundles/14-optional-components" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-optional-components-%s-0.0.1.tar.zst", e2e.Arch)) ociRef := "oci://localhost:888/test/bundles" - createLocal(t, bundleDir, e2e.Arch) - publishInsecure(t, bundlePath, ociRef) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("publish %s %s --insecure", bundlePath, ociRef)) t.Run("list variables for local tarball with no color", func(t *testing.T) { - cmd := strings.Split(fmt.Sprintf("inspect %s --list-variables --no-color", bundlePath), " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + stdout, _ := runCmd(t, fmt.Sprintf("inspect %s --list-variables --no-color", bundlePath)) require.Contains(t, stdout, "prometheus:\n variables: []\n") }) t.Run("list variables for local tarball with color", func(t *testing.T) { - cmd := strings.Split(fmt.Sprintf("inspect %s --list-variables", bundlePath), " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + stdout, _ := runCmd(t, fmt.Sprintf("inspect %s --list-variables", bundlePath)) require.Contains(t, stdout, "\x1b") }) t.Run("list variables for remote tarball", func(t *testing.T) { - cmd := strings.Split(fmt.Sprintf("inspect %s --list-variables --insecure", fmt.Sprintf("%s/optional-components:0.0.1", ociRef)), " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) - + stdout, _ := runCmd(t, fmt.Sprintf("inspect %s --list-variables --insecure", fmt.Sprintf("%s/optional-components:0.0.1", ociRef))) ansiRegex := regexp.MustCompile("\x1b\\[[0-9;]*[a-zA-Z]") cleaned := ansiRegex.ReplaceAllString(stdout, "") require.Contains(t, cleaned, "prometheus:\n variables: []\n") diff --git a/src/test/e2e/commands_test.go b/src/test/e2e/commands_test.go index 0ccaf602..9884c278 100644 --- a/src/test/e2e/commands_test.go +++ b/src/test/e2e/commands_test.go @@ -25,114 +25,47 @@ import ( // This file contains helpers for running UDS CLI commands (ie. uds create/deploy/etc with various flags and options) -func zarfPublish(t *testing.T, path string, reg string) { - args := strings.Split(fmt.Sprintf("zarf package publish %s oci://%s --insecure --oci-concurrency=10 -l debug --no-progress", path, reg), " ") - _, _, err := e2e.UDS(args...) - require.NoError(t, err) -} - -func createLocal(t *testing.T, bundlePath string, arch string) { - cmd := strings.Split(fmt.Sprintf("create %s --insecure --confirm -a %s", bundlePath, arch), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - -func createLocalError(bundlePath string, arch string) (stderr string) { - cmd := strings.Split(fmt.Sprintf("create %s --insecure --confirm -a %s", bundlePath, arch), " ") - _, stderr, _ = e2e.UDS(cmd...) - return stderr -} - -func createLocalWithOuputFlag(t *testing.T, bundlePath string, destPath string, arch string) { - cmd := strings.Split(fmt.Sprintf("create %s -o %s --insecure --confirm -a %s", bundlePath, destPath, arch), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - -func createRemoteInsecure(t *testing.T, bundlePath, registry, arch string) { - cmd := strings.Split(fmt.Sprintf("create %s -o %s --confirm --insecure -a %s", bundlePath, registry, arch), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - -func createRemote(t *testing.T, bundlePath, registry, arch string) { - cmd := strings.Split(fmt.Sprintf("create %s -o %s --confirm -a %s", bundlePath, registry, arch), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - func inspectRemoteInsecure(t *testing.T, ref string) { - cmd := strings.Split(fmt.Sprintf("inspect %s --insecure --sbom", ref), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) - _, err = os.Stat(config.BundleSBOMTar) + runCmd(t, fmt.Sprintf("inspect %s --insecure --sbom", ref)) + _, err := os.Stat(config.BundleSBOMTar) require.NoError(t, err) err = os.Remove(config.BundleSBOMTar) require.NoError(t, err) } func inspectRemote(t *testing.T, ref string) { - cmd := strings.Split(fmt.Sprintf("inspect %s --sbom", ref), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) - _, err = os.Stat(config.BundleSBOMTar) + runCmd(t, fmt.Sprintf("inspect %s --sbom", ref)) + _, err := os.Stat(config.BundleSBOMTar) require.NoError(t, err) err = os.Remove(config.BundleSBOMTar) require.NoError(t, err) } func inspectRemoteAndSBOMExtract(t *testing.T, ref string) { - cmd := strings.Split(fmt.Sprintf("inspect %s --insecure --sbom --extract", ref), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) - _, err = os.Stat(config.BundleSBOM) + runCmd(t, fmt.Sprintf("inspect %s --insecure --sbom --extract", ref)) + _, err := os.Stat(config.BundleSBOM) require.NoError(t, err) err = os.RemoveAll(config.BundleSBOM) require.NoError(t, err) } func inspectLocal(t *testing.T, tarballPath string) { - cmd := strings.Split(fmt.Sprintf("inspect %s --sbom --no-color", tarballPath), " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + stdout, _ := runCmd(t, fmt.Sprintf("inspect %s --sbom --no-color", tarballPath)) require.NotContains(t, stdout, "\x1b") - _, err = os.Stat(config.BundleSBOMTar) + _, err := os.Stat(config.BundleSBOMTar) require.NoError(t, err) err = os.Remove(config.BundleSBOMTar) require.NoError(t, err) } func inspectLocalAndSBOMExtract(t *testing.T, tarballPath string) { - cmd := strings.Split(fmt.Sprintf("inspect %s --sbom --extract", tarballPath), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) - _, err = os.Stat(config.BundleSBOM) + runCmd(t, fmt.Sprintf("inspect %s --sbom --extract", tarballPath)) + _, err := os.Stat(config.BundleSBOM) require.NoError(t, err) err = os.RemoveAll(config.BundleSBOM) require.NoError(t, err) } -func deploy(t *testing.T, tarballPath string) (stdout string, stderr string) { - cmd := strings.Split(fmt.Sprintf("deploy %s --retries 1 --confirm", tarballPath), " ") - stdout, stderr, err := e2e.UDS(cmd...) - require.NoError(t, err) - return stdout, stderr -} - -func devDeploy(t *testing.T, bundlePath string) (stdout string, stderr string) { - cmd := strings.Split(fmt.Sprintf("dev deploy %s", bundlePath), " ") - stdout, stderr, err := e2e.UDS(cmd...) - require.NoError(t, err) - return stdout, stderr -} - -func devDeployPackages(t *testing.T, tarballPath string, packages string) (stdout string, stderr string) { - cmd := strings.Split(fmt.Sprintf("dev deploy %s --packages %s", tarballPath, packages), " ") - stdout, stderr, err := e2e.UDS(cmd...) - require.NoError(t, err) - return stdout, stderr -} - func runCmd(t *testing.T, input string) (stdout string, stderr string) { cmd := strings.Split(input, " ") stdout, stderr, err := e2e.UDS(cmd...) @@ -140,68 +73,27 @@ func runCmd(t *testing.T, input string) (stdout string, stderr string) { return stdout, stderr } -func deployPackagesFlag(tarballPath string, packages string) (stdout string, stderr string) { - cmd := strings.Split(fmt.Sprintf("deploy %s --confirm -l=debug --packages %s", tarballPath, packages), " ") - stdout, stderr, _ = e2e.UDS(cmd...) - return stdout, stderr -} - -func deployResumeFlag(t *testing.T, tarballPath string) { - cmd := strings.Split(fmt.Sprintf("deploy %s --confirm -l=debug --resume", tarballPath), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - -func remove(t *testing.T, source string) { - cmd := strings.Split(fmt.Sprintf("remove %s --confirm --insecure", source), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - -func removePackagesFlag(tarballPath string, packages string) (stdout string, stderr string) { - cmd := strings.Split(fmt.Sprintf("remove %s --confirm --insecure --packages %s", tarballPath, packages), " ") - stdout, stderr, _ = e2e.UDS(cmd...) - return stdout, stderr -} - -func deployInsecure(t *testing.T, ref string) { - cmd := strings.Split(fmt.Sprintf("deploy %s --insecure --confirm", ref), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - -func removeInsecure(t *testing.T, remote string) { - cmd := strings.Split(fmt.Sprintf("remove %s --insecure --confirm", remote), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) +func runCmdWithErr(input string) (stdout string, stderr string, err error) { + cmd := strings.Split(input, " ") + stdout, stderr, err = e2e.UDS(cmd...) + return stdout, stderr, err } func deployAndRemoveLocalAndRemoteInsecure(t *testing.T, ref string, tarballPath string) { - var cmd []string // test both paths because we want to test that the pulled tarball works as well t.Run( "deploy+remove bundle via OCI", func(t *testing.T) { - cmd = strings.Split(fmt.Sprintf("deploy %s --insecure --confirm", ref), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) - - cmd = strings.Split(fmt.Sprintf("remove %s --confirm --insecure", ref), " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("deploy %s --insecure --confirm", ref)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", ref)) }, ) t.Run( "deploy+remove bundle via local tarball", func(t *testing.T) { - cmd = strings.Split(fmt.Sprintf("deploy %s --confirm", tarballPath), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) - - cmd = strings.Split(fmt.Sprintf("remove %s --confirm", tarballPath), " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("deploy %s --confirm", tarballPath)) + runCmd(t, fmt.Sprintf("remove %s --confirm", tarballPath)) }, ) } @@ -217,16 +109,12 @@ func pull(t *testing.T, ref string, tarballName string) { t.Fatalf("second arg to pull() must be the name a bundle tarball, got %s", tarballName) } // todo: output somewhere other than build? - cmd := strings.Split(fmt.Sprintf("pull %s -o build --insecure --oci-concurrency=10", ref), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("pull %s -o build --insecure --oci-concurrency=10", ref)) decompressed := "build/decompressed-bundle" defer e2e.CleanFiles(decompressed) - cmd = []string{"zarf", "tools", "archiver", "decompress", filepath.Join("build", tarballName), decompressed} - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("zarf tools archiver decompress %s %s", filepath.Join("build", tarballName), decompressed)) index := ocispec.Index{} b, err := os.ReadFile(filepath.Join(decompressed, "index.json")) @@ -260,18 +148,6 @@ func pull(t *testing.T, ref string, tarballName string) { } } -func publish(t *testing.T, bundlePath, ociPath string) { - cmd := strings.Split(fmt.Sprintf("publish %s %s --oci-concurrency=10", bundlePath, ociPath), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - -func publishInsecure(t *testing.T, bundlePath, ociPath string) { - cmd := strings.Split(fmt.Sprintf("publish %s %s --insecure", bundlePath, ociPath), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) -} - func queryIndex(t *testing.T, registryURL, bundlePath string) (ocispec.Index, error) { url := fmt.Sprintf("%s/v2/%s/manifests/0.0.1", registryURL, bundlePath) req, err := http.NewRequest("GET", url, nil) @@ -300,10 +176,8 @@ func queryIndex(t *testing.T, registryURL, bundlePath string) (ocispec.Index, er } func removeZarfInit() { - cmd := strings.Split("zarf tools kubectl delete namespace zarf", " ") - _, _, err := e2e.UDS(cmd...) + _, _, err := runCmdWithErr("zarf tools kubectl delete namespace zarf") message.WarnErr(err, "Failed to delete zarf namespace") - cmd = strings.Split("zarf tools kubectl delete mutatingwebhookconfiguration.admissionregistration.k8s.io/zarf", " ") - _, _, err = e2e.UDS(cmd...) + _, _, err = runCmdWithErr("zarf tools kubectl delete mutatingwebhookconfiguration.admissionregistration.k8s.io/zarf") message.WarnErr(err, "Failed to delete zarf webhook") } diff --git a/src/test/e2e/completion_test.go b/src/test/e2e/completion_test.go index eb3efe86..9c1c7e81 100644 --- a/src/test/e2e/completion_test.go +++ b/src/test/e2e/completion_test.go @@ -5,7 +5,6 @@ package test import ( - "strings" "testing" "github.com/defenseunicorns/uds-cli/src/config/lang" @@ -15,26 +14,22 @@ import ( func TestCompletion(t *testing.T) { t.Run("Test Completion", func(t *testing.T) { - cmd := strings.Split("completion", " ") - output, _, _ := e2e.UDS(cmd...) + output, _ := runCmd(t, "completion") require.Contains(t, output, lang.CompletionCmdLong) }) t.Run("Test Bash Completion", func(t *testing.T) { - cmd := strings.Split("completion bash", " ") - output, _, _ := e2e.UDS(cmd...) + output, _ := runCmd(t, "completion bash") require.Contains(t, output, "bash completion V2 for uds") }) t.Run("Test ZSH Completion", func(t *testing.T) { - cmd := strings.Split("completion zsh", " ") - output, _, _ := e2e.UDS(cmd...) + output, _ := runCmd(t, "completion zsh") require.Contains(t, output, "zsh completion for uds") }) t.Run("Test Fish Completion", func(t *testing.T) { - cmd := strings.Split("completion fish", " ") - output, _, _ := e2e.UDS(cmd...) + output, _ := runCmd(t, "completion fish") require.Contains(t, output, "fish completion for uds") }) } diff --git a/src/test/e2e/dev_test.go b/src/test/e2e/dev_test.go index e9a14798..c9bd9a0a 100644 --- a/src/test/e2e/dev_test.go +++ b/src/test/e2e/dev_test.go @@ -7,7 +7,6 @@ package test import ( "fmt" "path/filepath" - "strings" "testing" "github.com/stretchr/testify/require" @@ -18,89 +17,68 @@ func TestDevDeploy(t *testing.T) { removeZarfInit() t.Run("Test dev deploy with local and remote pkgs", func(t *testing.T) { - e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false) 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)) - devDeploy(t, bundleDir) + runCmd(t, fmt.Sprintf("dev deploy %s", bundleDir)) - cmd := strings.Split("zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'", " ") - deployments, _, _ := e2e.UDS(cmd...) + deployments, _ := runCmd(t, "zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'") require.Contains(t, deployments, "podinfo") require.Contains(t, deployments, "nginx") - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) }) t.Run("Test dev deploy with CreateLocalPkgs", func(t *testing.T) { - e2e.DeleteZarfPkg(t, "src/test/packages/podinfo") 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)) - devDeployPackages(t, bundleDir, "podinfo") + runCmd(t, fmt.Sprintf("dev deploy %s --packages %s", bundleDir, "podinfo")) - cmd := strings.Split("zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'", " ") - deployments, _, _ := e2e.UDS(cmd...) + deployments, _ := runCmd(t, "zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'") require.Contains(t, deployments, "podinfo") require.NotContains(t, deployments, "nginx") - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) }) t.Run("Test dev deploy with ref flag", func(t *testing.T) { e2e.DeleteZarfPkg(t, "src/test/packages/podinfo") bundleDir := "src/test/bundles/03-local-and-remote" - cmd := strings.Split(fmt.Sprintf("dev deploy %s --ref %s", bundleDir, "nginx=0.0.2"), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("dev deploy %s --ref %s", bundleDir, "nginx=0.0.2")) - cmd = strings.Split("zarf tools kubectl get deployment -n nginx nginx-deployment -o=jsonpath='{.spec.template.spec.containers[0].image}'", " ") - ref, _, err := e2e.UDS(cmd...) + ref, _ := runCmd(t, "zarf tools kubectl get deployment -n nginx nginx-deployment -o=jsonpath='{.spec.template.spec.containers[0].image}'") require.Contains(t, ref, "nginx:1.26.0") - require.NoError(t, err) - cmd = strings.Split("zarf tools kubectl delete ns podinfo nginx zarf", " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, "zarf tools kubectl delete ns podinfo nginx zarf") }) t.Run("Test dev deploy with flavor flag", func(t *testing.T) { e2e.DeleteZarfPkg(t, "src/test/packages/podinfo/flavors") bundleDir := "src/test/bundles/15-dev-deploy" - cmd := strings.Split(fmt.Sprintf("dev deploy %s --flavor %s", bundleDir, "podinfo=patchVersion3"), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("dev deploy %s --flavor %s", bundleDir, "podinfo=patchVersion3")) - cmd = strings.Split("zarf tools kubectl get deployment -n podinfo-flavor podinfo -o=jsonpath='{.spec.template.spec.containers[0].image}'", " ") - ref, _, err := e2e.UDS(cmd...) + ref, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo-flavor podinfo -o=jsonpath='{.spec.template.spec.containers[0].image}'") require.Contains(t, ref, "ghcr.io/stefanprodan/podinfo:6.6.3") - require.NoError(t, err) - cmd = strings.Split("zarf tools kubectl delete ns zarf podinfo-flavor", " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, "zarf tools kubectl delete ns zarf podinfo-flavor") }) + t.Run("Test dev deploy with global flavor", func(t *testing.T) { bundleDir := "src/test/bundles/15-dev-deploy" - cmd := strings.Split(fmt.Sprintf("dev deploy %s --flavor %s --force-create", bundleDir, "patchVersion3"), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("dev deploy %s --flavor %s --force-create", bundleDir, "patchVersion3")) - cmd = strings.Split("zarf tools kubectl get deployment -n podinfo-flavor podinfo -o=jsonpath='{.spec.template.spec.containers[0].image}'", " ") - ref, _, err := e2e.UDS(cmd...) + ref, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo-flavor podinfo -o=jsonpath='{.spec.template.spec.containers[0].image}'") require.Contains(t, ref, "ghcr.io/stefanprodan/podinfo:6.6.3") - require.NoError(t, err) - cmd = strings.Split("zarf tools kubectl delete ns zarf podinfo-flavor", " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, "zarf tools kubectl delete ns zarf podinfo-flavor") }) t.Run("Test dev deploy with flavor and force create", func(t *testing.T) { @@ -109,37 +87,27 @@ func TestDevDeploy(t *testing.T) { // create flavor patchVersion3 podinfo-flavor package pkgDir := "src/test/packages/podinfo" - cmd := strings.Split(fmt.Sprintf("zarf package create %s --flavor %s --confirm -o %s", pkgDir, "patchVersion3", pkgDir), " ") - _, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + + runCmd(t, fmt.Sprintf("zarf package create %s --flavor %s --confirm -o %s", pkgDir, "patchVersion3", pkgDir)) // dev deploy with flavor patchVersion2 and --force-create - cmd = strings.Split(fmt.Sprintf("dev deploy %s --flavor %s --force-create", bundleDir, "podinfo=patchVersion2"), " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("dev deploy %s --flavor %s --force-create", bundleDir, "podinfo=patchVersion2")) - cmd = strings.Split("zarf tools kubectl get deployment -n podinfo-flavor podinfo -o=jsonpath='{.spec.template.spec.containers[0].image}'", " ") - ref, _, err := e2e.UDS(cmd...) + ref, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo-flavor podinfo -o=jsonpath='{.spec.template.spec.containers[0].image}'") // assert that podinfo package with flavor patchVersion2 was deployed. require.Contains(t, ref, "ghcr.io/stefanprodan/podinfo:6.6.2") - require.NoError(t, err) - cmd = strings.Split("zarf tools kubectl delete ns zarf podinfo-flavor", " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, "zarf tools kubectl delete ns zarf podinfo-flavor") }) t.Run("Test dev deploy with remote bundle", func(t *testing.T) { - bundle := "oci://ghcr.io/defenseunicorns/packages/uds-cli/test/publish/ghcr-test:0.0.1" + runCmd(t, fmt.Sprintf("dev deploy %s", bundle)) - devDeploy(t, bundle) - - cmd := strings.Split("zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'", " ") - deployments, _, _ := e2e.UDS(cmd...) + deployments, _ := runCmd(t, "zarf tools kubectl get deployments -A -o=jsonpath='{.items[*].metadata.name}'") require.Contains(t, deployments, "podinfo") require.Contains(t, deployments, "nginx") - remove(t, bundle) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundle)) }) t.Run("Test dev deploy with --set flag", func(t *testing.T) { @@ -148,7 +116,7 @@ func TestDevDeploy(t *testing.T) { _, stderr := runCmd(t, "dev deploy "+bundleDir+" --set ANIMAL=Longhorns --set COUNTRY=Texas -l=debug") require.Contains(t, stderr, "This fun-fact was imported: Longhorns are the national animal of Texas") require.NotContains(t, stderr, "This fun-fact was imported: Unicorns are the national animal of Scotland") - remove(t, bundleTarballPath) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundleTarballPath)) }) // delete packages because other tests depend on them being created with SBOMs (ie. force other tests to re-create) diff --git a/src/test/e2e/ghcr_test.go b/src/test/e2e/ghcr_test.go index 6de4a123..d50eac97 100644 --- a/src/test/e2e/ghcr_test.go +++ b/src/test/e2e/ghcr_test.go @@ -34,16 +34,18 @@ func TestBundleCreateAndPublishGHCR(t *testing.T) { Reference: "0.0.1", } - createLocal(t, bundleDir, "arm64") - createLocal(t, bundleDir, "amd64") - publish(t, bundlePathARM, registryURL) + 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 --oci-concurrency=10", bundlePathARM, registryURL)) + // test without oci prefix registryURL = "ghcr.io/defenseunicorns/packages/uds-cli/test/publish" - publish(t, bundlePathAMD, registryURL) + runCmd(t, fmt.Sprintf("publish %s %s --oci-concurrency=10", bundlePathAMD, registryURL)) + inspectRemote(t, bundlePathARM) pull(t, bundleRef.String(), bundleTarballName) - deploy(t, bundleRef.String()) - remove(t, bundleRef.String()) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundleRef.String())) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundleRef.String())) // ensure the bundle index is present index, err := queryIndex(t, "https://ghcr.io", fmt.Sprintf("%s/%s", bundleGHCRPath, bundleName)) @@ -64,11 +66,13 @@ func TestBundleCreateRemoteAndDeployGHCR(t *testing.T) { Repository: "ghcr-test", Reference: "0.0.1", } - createRemote(t, bundleDir, registryURL, "arm64") - createRemote(t, bundleDir, registryURL, "amd64") + + runCmd(t, fmt.Sprintf("create %s -o %s --confirm -a %s", bundleDir, registryURL, "arm64")) + runCmd(t, fmt.Sprintf("create %s -o %s --confirm -a %s", bundleDir, registryURL, "amd64")) + inspectRemote(t, bundleRef.String()) - deploy(t, bundleRef.String()) - remove(t, bundleRef.String()) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundleRef.String())) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundleRef.String())) // ensure the bundle index is present index, err := queryIndex(t, "https://ghcr.io", fmt.Sprintf("%s/%s", bundleGHCRPath, bundleName)) diff --git a/src/test/e2e/main_test.go b/src/test/e2e/main_test.go index 2301983f..34019ff0 100644 --- a/src/test/e2e/main_test.go +++ b/src/test/e2e/main_test.go @@ -111,24 +111,18 @@ func deployZarfInit(t *testing.T) { bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-all-the-inits-%s-0.0.1.tar.zst", e2e.Arch)) // Create - cmd := strings.Split(fmt.Sprintf("create %s --confirm --insecure", bundleDir), " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("create %s --confirm --insecure", bundleDir)) // Deploy - cmd = strings.Split(fmt.Sprintf("deploy %s --confirm -l=debug", bundlePath), " ") - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("deploy %s --confirm -l=debug", bundlePath)) } } func zarfInitDeployed() bool { - cmd := strings.Split("zarf tools kubectl get deployments zarf-docker-registry --namespace zarf", " ") - _, stderr, _ := e2e.UDS(cmd...) + _, stderr, _ := runCmdWithErr("zarf tools kubectl get deployments zarf-docker-registry --namespace zarf") registryDeployed := !strings.Contains(stderr, "No resources found in zarf namespace") && !strings.Contains(stderr, "not found") - cmd = strings.Split("zarf tools kubectl get deployments agent-hook --namespace zarf", " ") - _, stderr, _ = e2e.UDS(cmd...) + _, stderr, _ = runCmdWithErr("zarf tools kubectl get deployments agent-hook --namespace zarf") agentDeployed := !strings.Contains(stderr, "No resources found in zarf namespace") && !strings.Contains(stderr, "not found") return registryDeployed && agentDeployed } diff --git a/src/test/e2e/monitor_test.go b/src/test/e2e/monitor_test.go index 199f7813..8400f406 100644 --- a/src/test/e2e/monitor_test.go +++ b/src/test/e2e/monitor_test.go @@ -5,7 +5,6 @@ package test import ( - "strings" "testing" "github.com/stretchr/testify/require" @@ -14,27 +13,26 @@ import ( func TestMonitor(t *testing.T) { // this test assumes a running k3d cluster with the UDS operator and admission controller installed // recommend running with uds run test:engine-e2e to install controllers - cmd := strings.Split("zarf tools kubectl get deployments -n pepr-system -o=jsonpath='{.items[*].metadata.name}'", " ") - deployments, _, _ := e2e.UDS(cmd...) + deployments, _ := runCmd(t, "zarf tools kubectl get deployments -n pepr-system -o=jsonpath='{.items[*].metadata.name}'") require.Contains(t, deployments, "pepr-uds-core") require.Contains(t, deployments, "pepr-uds-core-watcher") // we expect this command to fail because UDS Core doesn't allow some of the configs in this package - _, _, err := e2e.UDS("zarf", "dev", "deploy", "src/test/packages/engine", "--retries=1") + _, _, err := runCmdWithErr("zarf dev deploy src/test/packages/engine --retries=1") require.Error(t, err) t.Run("test mutated policies", func(t *testing.T) { - stdout, _, _ := e2e.UDS("monitor", "pepr", "mutated") + stdout, _ := runCmd(t, "monitor pepr mutated") require.Contains(t, stdout, "✎ MUTATED podinfo") }) t.Run("test allowed policies", func(t *testing.T) { - stdout, _, _ := e2e.UDS("monitor", "pepr", "allowed") + stdout, _ := runCmd(t, "monitor pepr allowed") require.Contains(t, stdout, "✓ ALLOWED podinfo") }) t.Run("test denied policies", func(t *testing.T) { - stdout, _, _ := e2e.UDS("monitor", "pepr", "denied") + stdout, _ := runCmd(t, "monitor pepr denied") require.Contains(t, stdout, "✗ DENIED podinfo") }) } diff --git a/src/test/e2e/optional_bundle_test.go b/src/test/e2e/optional_bundle_test.go index c07755c1..ada883c2 100644 --- a/src/test/e2e/optional_bundle_test.go +++ b/src/test/e2e/optional_bundle_test.go @@ -27,15 +27,15 @@ func TestBundleOptionalComponents(t *testing.T) { zarfPkgPath = "src/test/packages/prometheus" pkg := filepath.Join(zarfPkgPath, fmt.Sprintf("zarf-package-prometheus-%s-0.0.1.tar.zst", e2e.Arch)) e2e.CreateZarfPkg(t, zarfPkgPath, false) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) // create bundle and publish bundleDir := "src/test/bundles/14-optional-components" bundleName := "optional-components" bundleTarballName := fmt.Sprintf("uds-bundle-%s-%s-0.0.1.tar.zst", bundleName, e2e.Arch) bundlePath := filepath.Join(bundleDir, bundleTarballName) - createLocal(t, bundleDir, e2e.Arch) - publishInsecure(t, bundlePath, "localhost:888") + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("publish %s localhost:888 --insecure", bundlePath)) t.Run("look through contents of local bundle to ensure only selected components are present", func(t *testing.T) { // local pkgs will have a correct pkg manifest (ie. missing non-selected optional component tarballs) @@ -45,8 +45,8 @@ func TestBundleOptionalComponents(t *testing.T) { }) t.Run("test local deploy", func(t *testing.T) { - deploy(t, bundlePath) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) }) t.Run("test remote deploy + pulled deploy", func(t *testing.T) { @@ -69,9 +69,7 @@ func introspectOptionalComponentsBundle(t *testing.T) { // decompress the bundle bundlePath := fmt.Sprintf("src/test/bundles/14-optional-components/uds-bundle-optional-components-%s-0.0.1.tar.zst", e2e.Arch) - cmd := []string{"zarf", "tools", "archiver", "decompress", bundlePath, decompressionLoc} - _, _, err = e2e.UDS(cmd...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("zarf tools archiver decompress %s %s", bundlePath, decompressionLoc)) // read in the bundle's index.json index := ocispec.Index{} diff --git a/src/test/e2e/security_hub_test.go b/src/test/e2e/security_hub_test.go index 537c34cf..11d64f9a 100644 --- a/src/test/e2e/security_hub_test.go +++ b/src/test/e2e/security_hub_test.go @@ -5,6 +5,7 @@ package test import ( + "fmt" "os" "path/filepath" "testing" @@ -24,8 +25,7 @@ func TestScanCommand(t *testing.T) { defer os.RemoveAll(tempDir) outputFile := filepath.Join(tempDir, "zarf-init.csv") - _, stdErr, err := e2e.UDS("scan", "--org", "defenseunicorns", "--package-name", "packages/init", "--tag", "v0.34.0", "--output-file", outputFile) - require.NoError(t, err, stdErr) + _, stdErr := runCmd(t, fmt.Sprintf("scan --org defenseunicorns --package-name packages/init --tag v0.36.1 --output-file %s", outputFile)) require.FileExists(t, outputFile) fileInfo, err := os.Stat(outputFile) require.NoError(t, err) diff --git a/src/test/e2e/variable_test.go b/src/test/e2e/variable_test.go index 3b7f296d..03323766 100644 --- a/src/test/e2e/variable_test.go +++ b/src/test/e2e/variable_test.go @@ -9,7 +9,6 @@ import ( "fmt" "os" "path/filepath" - "strings" "testing" "github.com/stretchr/testify/require" @@ -24,17 +23,15 @@ func TestBundleVariables(t *testing.T) { t.Run("simple vars and global export", func(t *testing.T) { bundleDir := "src/test/bundles/02-variables" bundleTarballPath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-variables-%s-0.0.1.tar.zst", e2e.Arch)) - cmd := strings.Split(fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch), " ") - _, stderr, err := e2e.UDS(cmd...) - require.NoError(t, err) + _, stderr := runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) require.Contains(t, stderr, "failed strict unmarshalling") - _, stderr = deploy(t, bundleTarballPath) + _, stderr = runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundleTarballPath)) bundleVariablesTestChecks(t, stderr, bundleTarballPath) }) t.Run("bad var name in import", func(t *testing.T) { bundleDir := "src/test/bundles/02-variables/bad-var-name" - stderr := createLocalError(bundleDir, e2e.Arch) + _, stderr, _ := runCmdWithErr(fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) require.Contains(t, stderr, "does not have a matching export") }) @@ -42,8 +39,8 @@ func TestBundleVariables(t *testing.T) { e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var-collision", false) bundleDir := "src/test/bundles/02-variables/export-name-collision" bundleTarballPath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-export-name-collision-%s-0.0.1.tar.zst", e2e.Arch)) - createLocal(t, bundleDir, e2e.Arch) - _, stderr := deploy(t, bundleTarballPath) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + _, stderr := runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundleTarballPath)) require.Contains(t, stderr, "This fun-fact was imported: Daffodils are the national flower of Wales") require.NotContains(t, stderr, "This fun-fact was imported: Unicorns are the national animal of Scotland") }) @@ -82,100 +79,77 @@ func TestBundleWithHelmOverrides(t *testing.T) { err := os.Setenv("UDS_CONFIG", filepath.Join(bundleDir, "uds-config.yaml")) require.NoError(t, err) - createLocal(t, bundleDir, e2e.Arch) - deploy(t, bundlePath) + runCmd(t, fmt.Sprintf("create %s --confirm --insecure -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) // test values overrides t.Run("check values overrides", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.replicas}'", " ") - outputNumReplicas, _, err := e2e.UDS(cmd...) + outputNumReplicas, _ := runCmd(t, "zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.replicas}'") require.Equal(t, "'2'", outputNumReplicas) - require.NoError(t, err) }) t.Run("check object-type override in values", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.metadata.annotations}'", " ") - annotations, _, err := e2e.UDS(cmd...) + annotations, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.metadata.annotations}'") require.Contains(t, annotations, "\"customAnnotation\":\"customValue\"") - require.NoError(t, err) - }) t.Run("check list-type override in values", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.tolerations}'", " ") - tolerations, _, err := e2e.UDS(cmd...) + tolerations, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.tolerations}'") require.Contains(t, tolerations, "\"key\":\"uds\"") require.Contains(t, tolerations, "\"value\":\"defense\"") require.Contains(t, tolerations, "\"key\":\"unicorn\"") require.Contains(t, tolerations, "\"effect\":\"NoSchedule\"") - require.NoError(t, err) }) // test variables overrides t.Run("check variables overrides, use default", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deploy unicorn-podinfo -n podinfo -o=jsonpath='{.spec.template.spec.containers[*].command[*]}'", " ") - podCmd, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + podCmd, _ := runCmd(t, "zarf tools kubectl get deploy unicorn-podinfo -n podinfo -o=jsonpath='{.spec.template.spec.containers[*].command[*]}'") require.Contains(t, podCmd, "--level=debug") }) t.Run("check variables overrides, default overwritten by config", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'", " ") - outputUIColor, _, err := e2e.UDS(cmd...) + outputUIColor, _ := runCmd(t, "zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'") require.Equal(t, "'green, yellow'", outputUIColor) - require.NoError(t, err) }) t.Run("check variables overrides, no default but set in config", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_MESSAGE\")].value}'", " ") - outputMsg, _, err := e2e.UDS(cmd...) + outputMsg, _ := runCmd(t, "zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_MESSAGE\")].value}'") require.Equal(t, "'Hello Unicorn'", outputMsg) - require.NoError(t, err) }) t.Run("check variables overrides, no default and not set in config", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get secret test-secret -n podinfo -o jsonpath=\"{.data.test}\"", " ") - secretValue, _, err := e2e.UDS(cmd...) + secretValue, _ := runCmd(t, "zarf tools kubectl get secret test-secret -n podinfo -o jsonpath=\"{.data.test}\"") // expect the value to be from the underlying chart's values.yaml, no overrides require.Equal(t, "\"dGVzdC1zZWNyZXQ=\"", secretValue) - require.NoError(t, err) }) t.Run("check variables overrides with an object-type value", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].securityContext}'", " ") - securityContext, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + securityContext, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].securityContext}'") require.Contains(t, securityContext, "NET_ADMIN") require.Contains(t, securityContext, "\"runAsGroup\":4000") }) t.Run("check variables overrides with a list-type value", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get ingress -n podinfo unicorn-podinfo -o=jsonpath='{.spec.rules[*].host}''", " ") - hosts, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + hosts, _ := runCmd(t, "zarf tools kubectl get ingress -n podinfo unicorn-podinfo -o=jsonpath='{.spec.rules[*].host}''") require.Contains(t, hosts, "podinfo.burning.boats") require.Contains(t, hosts, "podinfo.unicorns") }) t.Run("check variables overrides with a file type value", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get secret -n podinfo test-file-secret -o=jsonpath={.data.test}", " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + stdout, _ := runCmd(t, "zarf tools kubectl get secret -n podinfo test-file-secret -o=jsonpath={.data.test}") decoded, err := base64.StdEncoding.DecodeString(stdout) require.NoError(t, err) require.Contains(t, string(decoded), "ssh-rsa") }) t.Run("check multiple charts under same component deploy", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get secret -n second-chart second-chart-secret -o=jsonpath={.data.test}", " ") - stdout, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + stdout, _ := runCmd(t, "zarf tools kubectl get secret -n second-chart second-chart-secret -o=jsonpath={.data.test}") decoded, err := base64.StdEncoding.DecodeString(stdout) require.NoError(t, err) require.Contains(t, string(decoded), "ssh-rsa") }) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) } func TestBundleWithHelmOverridesValuesFile(t *testing.T) { @@ -187,33 +161,26 @@ func TestBundleWithHelmOverridesValuesFile(t *testing.T) { err := os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/07-helm-overrides", "uds-config.yaml")) require.NoError(t, err) - createLocal(t, bundleDir, e2e.Arch) - deploy(t, bundlePath) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) // test values overrides t.Run("check values overrides", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.replicas}'", " ") - outputNumReplicas, _, err := e2e.UDS(cmd...) + outputNumReplicas, _ := runCmd(t, "zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.replicas}'") require.Equal(t, "'2'", outputNumReplicas) - require.NoError(t, err) }) t.Run("check object-type override in values", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.metadata.annotations}'", " ") - annotations, _, err := e2e.UDS(cmd...) + annotations, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.metadata.annotations}'") require.Contains(t, annotations, "\"customAnnotation\":\"customValue2\"") - require.NoError(t, err) }) t.Run("check list-type override in values", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.tolerations}'", " ") - tolerations, _, err := e2e.UDS(cmd...) + tolerations, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.tolerations}'") require.Contains(t, tolerations, "\"key\":\"uds\"") require.Contains(t, tolerations, "\"value\":\"defense\"") require.Contains(t, tolerations, "\"key\":\"unicorn\"") require.Contains(t, tolerations, "\"effect\":\"NoSchedule\"") - require.NoError(t, err) - }) } @@ -226,38 +193,37 @@ func TestBundleWithDupPkgs(t *testing.T) { e2e.CreateZarfPkg(t, zarfPkgPath, false) name := "duplicates" pkg := filepath.Join(zarfPkgPath, fmt.Sprintf("zarf-package-helm-overrides-%s-0.0.1.tar.zst", e2e.Arch)) - zarfPublish(t, pkg, "localhost:888") + runCmd(t, fmt.Sprintf("zarf package publish %s oci://localhost:888 --insecure --oci-concurrency=10 -l debug --no-progress", pkg)) bundleDir := "src/test/bundles/07-helm-overrides/duplicate" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-%s-%s-0.0.1.tar.zst", name, e2e.Arch)) - createLocal(t, bundleDir, e2e.Arch) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) // remove namespace after tests defer func() { - cmd := strings.Split("zarf tools kubectl delete ns override-ns another-override-ns", " ") - _, _, _ = e2e.UDS(cmd...) + runCmd(t, "zarf tools kubectl delete ns override-ns another-override-ns") }() // helper fn to check the different namespaces for the deployment checkDeployments := func(t *testing.T) { for _, ns := range []string{"override-ns", "another-override-ns"} { - cmd := strings.Split(fmt.Sprintf("zarf tools kubectl get deploy -n %s -o=jsonpath='{.items[*].metadata.name}'", ns), " ") - deployment, _, _ := e2e.UDS(cmd...) + deployment, _ := runCmd(t, fmt.Sprintf("zarf tools kubectl get deploy -n %s -o=jsonpath='{.items[*].metadata.name}'", ns)) require.Equal(t, "'unicorn-podinfo'", deployment) } } t.Run("test namespace override + dup pkgs in local bundle", func(t *testing.T) { - deploy(t, bundlePath) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) checkDeployments(t) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) }) t.Run("test namespace override + dup pkgs in remote bundle", func(t *testing.T) { - publishInsecure(t, bundlePath, "localhost:888") - deployInsecure(t, fmt.Sprintf("localhost:888/%s:0.0.1", name)) + ref := fmt.Sprintf("localhost:888/%s:0.0.1", name) + runCmd(t, fmt.Sprintf("publish %s localhost:888 --insecure", bundlePath)) + runCmd(t, fmt.Sprintf("deploy %s --insecure --confirm", ref)) checkDeployments(t) - removeInsecure(t, fmt.Sprintf("localhost:888/%s:0.0.1", name)) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", ref)) }) } @@ -280,40 +246,30 @@ func TestBundleWithEnvVarHelmOverrides(t *testing.T) { // create and deploy bundle bundleDir := "src/test/bundles/07-helm-overrides" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-helm-overrides-%s-0.0.1.tar.zst", e2e.Arch)) - createLocal(t, bundleDir, e2e.Arch) - deploy(t, bundlePath) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) t.Run("check override variables, ensure they are coming from env vars and take highest precedence", func(t *testing.T) { - cmd := strings.Split("z tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'", " ") - outputUIColor, _, err := e2e.UDS(cmd...) + outputUIColor, _ := runCmd(t, "z tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'") require.Equal(t, fmt.Sprintf("'%s'", color), outputUIColor) - require.NoError(t, err) }) t.Run("check override secret val", func(t *testing.T) { - cmd := strings.Split("z tools kubectl get secret test-secret -n podinfo -o jsonpath=\"{.data.test}\"", " ") - secretValue, _, err := e2e.UDS(cmd...) + secretValue, _ := runCmd(t, "z tools kubectl get secret test-secret -n podinfo -o jsonpath=\"{.data.test}\"") require.Equal(t, fmt.Sprintf("\"%s\"", b64Secret), secretValue) - require.NoError(t, err) }) t.Run("ensure --set overrides take precedence over env vars", func(t *testing.T) { - deployCmd := fmt.Sprintf("deploy %s --set UI_COLOR=orange --set helm-overrides.ui_msg=foo --confirm", bundlePath) - _, _, err := e2e.UDS(strings.Split(deployCmd, " ")...) - require.NoError(t, err) + runCmd(t, fmt.Sprintf("deploy %s --set UI_COLOR=orange --set helm-overrides.ui_msg=foo --confirm", bundlePath)) - cmd := strings.Split("z tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'", " ") - outputUIColor, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + outputUIColor, _ := runCmd(t, "z tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'") require.Equal(t, "'orange'", outputUIColor) - cmd = strings.Split("z tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_MESSAGE\")].value}'", " ") - outputMsg, _, err := e2e.UDS(cmd...) - require.NoError(t, err) + outputMsg, _ := runCmd(t, "z tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_MESSAGE\")].value}'") require.Equal(t, "'foo'", outputMsg) }) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) } func TestVariablePrecedence(t *testing.T) { @@ -326,19 +282,17 @@ func TestVariablePrecedence(t *testing.T) { bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-var-precedence-%s-0.0.1.tar.zst", e2e.Arch)) err := os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/08-var-precedence", "uds-config.yaml")) require.NoError(t, err) - createLocal(t, bundleDir, e2e.Arch) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) color := "green" err = os.Setenv("UDS_UI_COLOR", color) require.NoError(t, err) - _, stderr := deploy(t, bundlePath) + _, stderr := runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) t.Run("test precedence, env var > uds-config.variables > uds-config.shared", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'", " ") // test env har taking highest precedence - outputUIColor, _, err := e2e.UDS(cmd...) + outputUIColor, _ := runCmd(t, "zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'") require.Equal(t, fmt.Sprintf("'%s'", color), outputUIColor) - require.NoError(t, err) // test uds-config.variables overriding a shared var require.Contains(t, stderr, "shared var in output-var pkg: unicorns.uds.dev") @@ -348,13 +302,11 @@ func TestVariablePrecedence(t *testing.T) { }) t.Run("test uds-config.shared overriding values in a Helm chart (ie. bundle overrides)", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deploy unicorn-podinfo -n podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_BACKEND_URL\")].value}'", " ") - backend, _, err := e2e.UDS(cmd...) + backend, _ := runCmd(t, "zarf tools kubectl get deploy unicorn-podinfo -n podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_BACKEND_URL\")].value}'") require.Equal(t, fmt.Sprintf("'%s'", "burning.boats"), backend) - require.NoError(t, err) }) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) } func TestExportVarsAsGlobalVars(t *testing.T) { @@ -365,32 +317,26 @@ func TestExportVarsAsGlobalVars(t *testing.T) { bundleDir := "src/test/bundles/12-exported-pkg-vars" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-export-vars-%s-0.0.1.tar.zst", e2e.Arch)) - createLocal(t, bundleDir, e2e.Arch) - deploy(t, bundlePath) + runCmd(t, fmt.Sprintf("create %s --insecure --confirm -a %s", bundleDir, e2e.Arch)) + runCmd(t, fmt.Sprintf("deploy %s --retries 1 --confirm", bundlePath)) t.Run("check templated variables overrides in values", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'", " ") - outputUIColor, _, err := e2e.UDS(cmd...) + outputUIColor, _ := runCmd(t, "zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'") require.Equal(t, "'orange'", outputUIColor) - require.NoError(t, err) }) t.Run("check multiple templated variables as object overrides in values", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.metadata.annotations}'", " ") - annotations, _, err := e2e.UDS(cmd...) + annotations, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.metadata.annotations}'") require.Contains(t, annotations, "\"customAnnotation\":\"orangeAnnotation\"") - require.NoError(t, err) }) t.Run("check templated variable list-type overrides in values", func(t *testing.T) { - cmd := strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.tolerations}'", " ") - tolerations, _, err := e2e.UDS(cmd...) + tolerations, _ := runCmd(t, "zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.tolerations}'") require.Contains(t, tolerations, "\"key\":\"uds\"") require.Contains(t, tolerations, "\"value\":\"true\"") require.Contains(t, tolerations, "\"key\":\"unicorn\"") require.Contains(t, tolerations, "\"value\":\"defense\"") - require.NoError(t, err) }) - remove(t, bundlePath) + runCmd(t, fmt.Sprintf("remove %s --confirm --insecure", bundlePath)) } diff --git a/src/test/e2e/zarf_test.go b/src/test/e2e/zarf_test.go index 1d41c392..15288021 100644 --- a/src/test/e2e/zarf_test.go +++ b/src/test/e2e/zarf_test.go @@ -17,10 +17,8 @@ import ( // TestZarfLint tests to ensure that the `zarf dev lint` command functions (which requires the zarf schema to be embedded in main.go) func TestZarfLint(t *testing.T) { - cmd := strings.Split("zarf dev lint src/test/packages/podinfo", " ") - _, stdErr, err := e2e.UDS(cmd...) - require.NoError(t, err) - require.Contains(t, stdErr, "Image not pinned with digest - ghcr.io/stefanprodan/podinfo:6.4.0") + _, stderr := runCmd(t, "zarf dev lint src/test/packages/podinfo") + require.Contains(t, stderr, "Image not pinned with digest - ghcr.io/stefanprodan/podinfo:6.4.0") } func TestZarfToolsVersions(t *testing.T) { @@ -56,9 +54,7 @@ func TestZarfToolsVersions(t *testing.T) { } for _, tt := range tests { - cmdArgs := fmt.Sprintf("zarf tools %s version", tt.args.tool) - res, stdErr, err := e2e.UDS(strings.Split(cmdArgs, " ")...) - require.NoError(t, err) + res, stderr := runCmd(t, fmt.Sprintf("zarf tools %s version", tt.args.tool)) toolRepoVerArgs := fmt.Sprintf("list -f '{{.Version}}' -m %s", tt.args.toolRepo) verRes, _, verErr := exec.Cmd("go", strings.Split(toolRepoVerArgs, " ")...) @@ -67,7 +63,7 @@ func TestZarfToolsVersions(t *testing.T) { toolVersion := strings.Split(verRes, "'")[1] output := res if res == "" { - output = stdErr + output = stderr } require.Contains(t, output, toolVersion) } diff --git a/tasks/tests.yaml b/tasks/tests.yaml index 0d88ec60..8f0a75d5 100644 --- a/tasks/tests.yaml +++ b/tasks/tests.yaml @@ -33,7 +33,7 @@ tasks: - name: completion description: only run tests in completion_test.go actions: - - cmd: cd src/test/e2e && go test -failfast -v -timeout 30m completion_test.go main_test.go + - cmd: cd src/test/e2e && go test -failfast -v -timeout 30m completion_test.go commands_test.go main_test.go - name: dev description: only run tests in dev.go