Skip to content

Commit

Permalink
chore: ensure NoError e2e.CleanFiles and pass thru testing.T
Browse files Browse the repository at this point in the history
Signed-off-by: Kit Patella <[email protected]>
  • Loading branch information
mkcp committed Sep 30, 2024
1 parent 93417ee commit cc6b253
Show file tree
Hide file tree
Showing 23 changed files with 46 additions and 49 deletions.
7 changes: 2 additions & 5 deletions src/test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bufio"
"errors"
"fmt"
"log/slog"
"os"
"regexp"
"runtime"
Expand Down Expand Up @@ -95,12 +94,10 @@ func (e2e *ZarfE2ETest) Kubectl(t *testing.T, args ...string) (string, string, e
}

// CleanFiles removes files and directories that have been created during the test.
func (e2e *ZarfE2ETest) CleanFiles(files ...string) {
func (e2e *ZarfE2ETest) CleanFiles(t *testing.T, files ...string) {
for _, file := range files {
err := os.RemoveAll(file)
if err != nil {
slog.Debug("Unable to cleanup files", "files", files, "error", err)
}
require.NoError(t, err)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/e2e/00_use_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func TestUseCLI(t *testing.T) {
expectedShasum := "61b50898f982d015ed87093ba822de0fe011cec6dd67db39f99d8c56391a6109\n"
shasumTestFilePath := "shasum-test-file"

e2e.CleanFiles(shasumTestFilePath)
e2e.CleanFiles(t, shasumTestFilePath)
t.Cleanup(func() {
e2e.CleanFiles(shasumTestFilePath)
e2e.CleanFiles(t, shasumTestFilePath)
})

err := os.WriteFile(shasumTestFilePath, []byte("random test data 🦄\n"), helpers.ReadWriteUser)
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestUseCLI(t *testing.T) {
require.FileExists(t, "binaries/eksctl_Darwin_arm64")
require.FileExists(t, "binaries/eksctl_Linux_x86_64")

e2e.CleanFiles("binaries/eksctl_Darwin_x86_64", "binaries/eksctl_Darwin_arm64", "binaries/eksctl_Linux_x86_64", path, "eks.yaml")
e2e.CleanFiles(t, "binaries/eksctl_Darwin_x86_64", "binaries/eksctl_Darwin_arm64", "binaries/eksctl_Linux_x86_64", path, "eks.yaml")
})

t.Run("zarf package create with tmpdir and cache", func(t *testing.T) {
Expand All @@ -165,7 +165,7 @@ func TestUseCLI(t *testing.T) {
secondFile = "second-choice-file.txt"
)
t.Cleanup(func() {
e2e.CleanFiles(firstFile, secondFile)
e2e.CleanFiles(t, firstFile, secondFile)
})
path := fmt.Sprintf("build/zarf-package-component-choice-%s.tar.zst", e2e.Arch)
stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--tmpdir", tmpdir, "--log-level=debug", "--confirm")
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestUseCLI(t *testing.T) {
tlsCert := "tls.crt"
tlsKey := "tls.key"
t.Cleanup(func() {
e2e.CleanFiles(tlsCA, tlsCert, tlsKey)
e2e.CleanFiles(t, tlsCA, tlsCert, tlsKey)
})
stdOut, stdErr, err := e2e.Zarf(t, "tools", "gen-pki", "github.com", "--sub-alt-name", "google.com")
require.NoError(t, err, stdOut, stdErr)
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/01_component_choice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestComponentChoice(t *testing.T) {
secondFile = "second-choice-file.txt"
)
t.Cleanup(func() {
e2e.CleanFiles(firstFile, secondFile)
e2e.CleanFiles(t, firstFile, secondFile)
})

path := fmt.Sprintf("build/zarf-package-component-choice-%s.tar.zst", e2e.Arch)
Expand Down
10 changes: 5 additions & 5 deletions src/test/e2e/02_component_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func TestComponentActions(t *testing.T) {
}

allArtifacts := append(deployArtifacts, createArtifacts...)
e2e.CleanFiles(allArtifacts...)
defer e2e.CleanFiles(allArtifacts...)
e2e.CleanFiles(t, allArtifacts...)
defer e2e.CleanFiles(t, allArtifacts...)

/* Create */
// Try creating the package to test the onCreate actions.
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestComponentActions(t *testing.T) {
require.FileExists(t, deployWithEnvVarArtifact)

// Remove the env var file at the end of the test
e2e.CleanFiles(deployWithEnvVarArtifact)
e2e.CleanFiles(t, deployWithEnvVarArtifact)
})

t.Run("action on-deploy-with-template", func(t *testing.T) {
Expand All @@ -128,7 +128,7 @@ func TestComponentActions(t *testing.T) {
require.Contains(t, string(outTemplated), "The snake says ###ZARF_VAR_SNAKE_SOUND###")

// Remove the templated file so we can test with dynamic variables
e2e.CleanFiles(deployTemplatedArtifact)
e2e.CleanFiles(t, deployTemplatedArtifact)

// Test using a templated file with dynamic variables
stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-with-template-use-of-variable,on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "--confirm")
Expand All @@ -140,7 +140,7 @@ func TestComponentActions(t *testing.T) {
require.Contains(t, string(outTemplated), "The snake says hiss")

// Remove the templated file at the end of the test
e2e.CleanFiles(deployTemplatedArtifact)
e2e.CleanFiles(t, deployTemplatedArtifact)
})

t.Run("action on-deploy-immediate-failure", func(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions src/test/e2e/03_deprecations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func TestDeprecatedComponentScripts(t *testing.T) {
"test-deprecated-deploy-after-hook.txt",
}
allArtifacts := append(deployArtifacts, prepareArtifact)
e2e.CleanFiles(allArtifacts...)
defer e2e.CleanFiles(allArtifacts...)
e2e.CleanFiles(t, allArtifacts...)
defer e2e.CleanFiles(t, allArtifacts...)

// 1. Try creating the package to test the create scripts
testPackagePath := fmt.Sprintf("%s/zarf-package-deprecated-component-scripts-%s.tar.zst", testPackageDirPath, e2e.Arch)
outputFlag := fmt.Sprintf("-o=%s", testPackageDirPath)
stdOut, stdErr, err := e2e.Zarf(t, "package", "create", testPackageDirPath, outputFlag, "--confirm")
defer e2e.CleanFiles(testPackagePath)
defer e2e.CleanFiles(t, testPackagePath)
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdErr, "Component '1-test-deprecated-prepare-scripts' is using scripts")
require.Contains(t, stdErr, "Component '2-test-deprecated-deploy-scripts' is using scripts")
Expand Down Expand Up @@ -71,8 +71,8 @@ func TestDeprecatedSetAndPackageVariables(t *testing.T) {
"test-deprecated-deploy-after-hook.txt",
}
allArtifacts := append(deployArtifacts, prepareArtifact)
e2e.CleanFiles(allArtifacts...)
defer e2e.CleanFiles(allArtifacts...)
e2e.CleanFiles(t, allArtifacts...)
defer e2e.CleanFiles(t, allArtifacts...)

// 2. Try creating the package to test the create scripts
testPackagePath := fmt.Sprintf("%s/zarf-package-deprecated-set-variable-%s.tar.zst", testPackageDirPath, e2e.Arch)
Expand All @@ -85,7 +85,7 @@ func TestDeprecatedSetAndPackageVariables(t *testing.T) {

// Check that the command displays a warning on create
stdOut, stdErr, err = e2e.Zarf(t, "package", "create", testPackageDirPath, outputFlag, "--confirm", "--set", "ECHO=Zarf-The-Axolotl")
defer e2e.CleanFiles(testPackagePath)
defer e2e.CleanFiles(t, testPackagePath)
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdErr, "Component '1-test-deprecated-set-variable' is using setVariable")
require.Contains(t, stdErr, "deprecated syntax ###ZARF_PKG_VAR_ECHO###")
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/04_create_templating_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ func TestCreateTemplating(t *testing.T) {
require.NoError(t, err)
require.Contains(t, string(filesJSON), "pandas")

e2e.CleanFiles(pkgName, fileFoldersPkgName)
e2e.CleanFiles(t, pkgName, fileFoldersPkgName)
}
8 changes: 4 additions & 4 deletions src/test/e2e/05_tarball_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMultiPartPackage(t *testing.T) {
outputFile = "multi-part-demo.dat"
)

e2e.CleanFiles(deployPath, outputFile)
e2e.CleanFiles(t, deployPath, outputFile)

// Create the package with a max size of 20MB
stdOut, stdErr, err := e2e.Zarf(t, "package", "create", createPath, "--max-package-size=20", "--confirm")
Expand Down Expand Up @@ -73,8 +73,8 @@ func TestMultiPartPackage(t *testing.T) {
err = helpers.SHAsMatch(parts[0], pkgData.Sha256Sum)
require.NoError(t, err)

e2e.CleanFiles(parts...)
e2e.CleanFiles(outputFile)
e2e.CleanFiles(t, parts...)
e2e.CleanFiles(t, outputFile)
}

func TestReproducibleTarballs(t *testing.T) {
Expand All @@ -98,7 +98,7 @@ func TestReproducibleTarballs(t *testing.T) {
err = utils.ReadYaml(filepath.Join(unpack1, layout.ZarfYAML), &pkg1)
require.NoError(t, err)

e2e.CleanFiles(unpack1, tb)
e2e.CleanFiles(t, unpack1, tb)

stdOut, stdErr, err = e2e.Zarf(t, "package", "create", createPath, "--confirm", "--output", tmp)
require.NoError(t, err, stdOut, stdErr)
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/06_create_sbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestCreateSBOM(t *testing.T) {
require.FileExists(t, filepath.Join(sbomPath, "dos-games", "ghcr.io_zarf-dev_doom-game_0.0.1.json"))

// Clean the SBOM path so it is force to be recreated
e2e.CleanFiles(sbomPath)
e2e.CleanFiles(t, sbomPath)

stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, "--sbom-out", sbomPath)
require.NoError(t, err, stdOut, stdErr)
Expand Down Expand Up @@ -68,5 +68,5 @@ func TestCreateSBOM(t *testing.T) {
_, err = os.ReadFile(filepath.Join(sbomPath, "init", "compare.html"))
require.NoError(t, err)

e2e.CleanFiles(pkgName)
e2e.CleanFiles(t, pkgName)
}
2 changes: 1 addition & 1 deletion src/test/e2e/07_create_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestCreateGit(t *testing.T) {
path := fmt.Sprintf("build/zarf-package-git-data-%s-0.0.1.tar.zst", e2e.Arch)
stdOut, stdErr, err := e2e.Zarf(t, "tools", "archiver", "decompress", path, extractDir, "--unarchive-all")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(extractDir)
defer e2e.CleanFiles(t, extractDir)

// Verify the full-repo component
gitDir := fmt.Sprintf("%s/components/full-repo/repos/zarf-public-test-2395699829/.git", extractDir)
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/08_create_differential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCreateDifferential(t *testing.T) {
// Build the package a first time
stdOut, stdErr, err := e2e.Zarf(t, "package", "create", packagePath, "--set=PACKAGE_VERSION=v0.25.0", "--confirm")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(packageName)
defer e2e.CleanFiles(t, packageName)

// Build the differential package without changing the version
_, stdErr, err = e2e.Zarf(t, "package", "create", packagePath, "--set=PACKAGE_VERSION=v0.25.0", differentialFlag, "--confirm")
Expand All @@ -40,7 +40,7 @@ func TestCreateDifferential(t *testing.T) {
// Build the differential package
stdOut, stdErr, err = e2e.Zarf(t, "package", "create", packagePath, "--set=PACKAGE_VERSION=v0.26.0", differentialFlag, "--confirm")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(differentialPackageName)
defer e2e.CleanFiles(t, differentialPackageName)

// Extract the yaml of the differential package
err = archiver.Extract(differentialPackageName, layout.ZarfYAML, tmpdir)
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/11_oci_pull_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (suite *PullInspectTestSuite) SetupSuite() {

func (suite *PullInspectTestSuite) TearDownSuite() {
local := fmt.Sprintf("zarf-package-dos-games-%s-1.0.0.tar.zst", e2e.Arch)
e2e.CleanFiles(local)
e2e.CleanFiles(suite.T(), local)
}

func (suite *PullInspectTestSuite) Test_0_Pull() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/20_zarf_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestZarfInit(t *testing.T) {
expectedErrorMessage = "unable to run component before action: command \"Check that the host architecture matches the package architecture\""
)
t.Cleanup(func() {
e2e.CleanFiles(mismatchedInitPackage)
e2e.CleanFiles(t, mismatchedInitPackage)
})

if runtime.GOOS == "linux" {
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/22_git_and_gitops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestGit(t *testing.T) {
require.NoError(t, err, stdOut, stdErr)

path := fmt.Sprintf("build/zarf-package-git-data-test-%s-1.0.0.tar.zst", e2e.Arch)
defer e2e.CleanFiles(path)
defer e2e.CleanFiles(t, path)

// Deploy the git data example (with component globbing to test that as well)
stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=full-repo,specific-*", "--confirm")
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/24_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestVariables(t *testing.T) {

tfPath := "modified-terraform.tf"

e2e.CleanFiles(tfPath, evilPath)
e2e.CleanFiles(t, tfPath, evilPath)

// Test that specifying an invalid setVariable value results in an error
stdOut, stdErr, err := e2e.Zarf(t, "package", "create", evilSrc, "--set", "NUMB3R5=K1TT3H", "--confirm")
Expand Down Expand Up @@ -93,5 +93,5 @@ func TestVariables(t *testing.T) {
stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", path, "--confirm")
require.NoError(t, err, stdOut, stdErr)

e2e.CleanFiles(tfPath, evilPath)
e2e.CleanFiles(t, tfPath, evilPath)
}
2 changes: 1 addition & 1 deletion src/test/e2e/25_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func testHelmChartsExample(t *testing.T) {
localTgzChartPath := filepath.Join("src", "test", "packages", "25-local-tgz-chart")
stdOut, stdErr, err := e2e.Zarf(t, "package", "create", localTgzChartPath, "--tmpdir", tmpdir, "--confirm")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(fmt.Sprintf("zarf-package-helm-charts-local-tgz-%s-0.0.1.tar.zst", e2e.Arch))
defer e2e.CleanFiles(t, fmt.Sprintf("zarf-package-helm-charts-local-tgz-%s-0.0.1.tar.zst", e2e.Arch))

// Create a package that needs dependencies
evilChartDepsPath := filepath.Join("src", "test", "packages", "25-evil-chart-deps")
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/29_config_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestConfigFile(t *testing.T) {
envKey = "ZARF_CONFIG"
)

e2e.CleanFiles(path)
e2e.CleanFiles(t, path)

// Test the config file environment variable
t.Setenv(envKey, filepath.Join(dir, config))
Expand All @@ -38,7 +38,7 @@ func TestConfigFile(t *testing.T) {
require.NoError(t, err, stdOut, stdErr)

// Cleanup
e2e.CleanFiles(path)
e2e.CleanFiles(t, path)
}

func configFileTests(t *testing.T, dir, path string) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/30_component_action_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestComponentActionEdgeCases(t *testing.T) {

stdOut, stdErr, err := e2e.Zarf(t, "package", "create", sourcePath, "--confirm")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(packagePath)
defer e2e.CleanFiles(t, packagePath)

stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", packagePath, "--confirm")
require.NoError(t, err, stdOut, stdErr)
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/31_checksum_and_signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestChecksumAndSignature(t *testing.T) {

stdOut, stdErr, err := e2e.Zarf(t, "package", "create", testPackageDirPath, privateKeyFlag, "--confirm")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(pkgName)
defer e2e.CleanFiles(t, pkgName)

// Test that we don't get an error when we remember to provide the public key
stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, publicKeyFlag)
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/32_component_webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestComponentWebhooks(t *testing.T) {
require.NoError(t, err, stdOut, stdErr)
stdOut, stdErr, err = e2e.Zarf(t, "tools", "wait-for", "deployment", "pepr-cb5693ef-d13c-5fe1-b5ad-c870fd911b3b", "available", "-n=pepr-system")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(webhookPath)
defer e2e.CleanFiles(t, webhookPath)

// Ensure package deployments wait for webhooks to complete.
gamesPath := fmt.Sprintf("build/zarf-package-dos-games-%s-1.1.0.tar.zst", e2e.Arch)
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/33_manifest_with_symlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func TestManifestWithSymlink(t *testing.T) {

path := fmt.Sprintf("build/zarf-package-manifest-with-symlink-%s-0.0.1.tar.zst", e2e.Arch)
require.FileExists(t, path)
defer e2e.CleanFiles(path)
defer e2e.CleanFiles(t, path)

stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--confirm")
defer e2e.CleanFiles("temp/manifests")
defer e2e.CleanFiles(t, "temp/manifests")
require.NoError(t, err, stdOut, stdErr)
require.FileExists(t, "temp/manifests/resources/img", "Symlink does not exist in the package as expected.")
}
2 changes: 1 addition & 1 deletion src/test/e2e/34_custom_init_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestCustomInit(t *testing.T) {

stdOut, stdErr, err := e2e.Zarf(t, "package", "create", buildPath, privateKeyFlag, "--confirm")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(pkgName)
defer e2e.CleanFiles(t, pkgName)

/* Test operations during package inspect */
// Test that we can inspect the yaml of the package without the private key
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/50_oci_publish_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (suite *PublishDeploySuiteTestSuite) SetupSuite() {

func (suite *PublishDeploySuiteTestSuite) TearDownSuite() {
local := fmt.Sprintf("zarf-package-helm-charts-%s-0.0.1.tar.zst", e2e.Arch)
e2e.CleanFiles(local)
e2e.CleanFiles(suite.Suite.T(), local)
}

func (suite *PublishDeploySuiteTestSuite) Test_0_Publish() {
Expand Down Expand Up @@ -103,7 +103,7 @@ func (suite *PublishDeploySuiteTestSuite) Test_2_Pull_And_Deploy() {
suite.T().Log("E2E: Package Pull oci:// && Package Deploy tarball")

local := fmt.Sprintf("zarf-package-helm-charts-%s-0.0.1.tar.zst", e2e.Arch)
defer e2e.CleanFiles(local)
defer e2e.CleanFiles(suite.T(), local)
// Verify the package was pulled.
suite.FileExists(local)

Expand Down
2 changes: 1 addition & 1 deletion src/test/nightly/ecr_publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestECRPublishing(t *testing.T) {
// Validate that we can pull the package down from ECR
stdOut, stdErr, err = e2e.Zarf(t, "package", "pull", upstreamPackageURL)
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(testPackageFileName)
defer e2e.CleanFiles(t, testPackageFileName)

// Ensure we get a warning when trying to inspect the package without providing the public key
// and the insecure flag
Expand Down

0 comments on commit cc6b253

Please sign in to comment.