Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: default to temp zarf cache in e2e tests #2355

Merged
merged 7 commits into from Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/test/common.go
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -71,6 +72,16 @@ func (e2e *ZarfE2ETest) Zarf(args ...string) (string, string, error) {
defer os.RemoveAll(tmpdir)
args = append(args, "--tmpdir", tmpdir)
}
if !slices.Contains(args, "--zarf-cache") && !slices.Contains(args, "tools") {
if os.Getenv("CI") == "true" {
// We make the cache dir relative to the working directory to make it work on the Windows Runners
// - they use two drives which filepath.Rel cannot cope with.
relCacheDir, _ := filepath.Abs(".cache-location")
args = append(args, "--zarf-cache", relCacheDir)
defer os.RemoveAll(relCacheDir)
}

}
return exec.CmdWithContext(context.TODO(), exec.PrintCfg(), e2e.ZarfBinPath, args...)
}

Expand Down
5 changes: 2 additions & 3 deletions src/test/e2e/04_create_templating_test.go
Expand Up @@ -18,19 +18,18 @@ func TestCreateTemplating(t *testing.T) {

// run `zarf package create` with a specified image cache location
tmpdir := t.TempDir()
cachePath := filepath.Join(tmpdir, ".cache-location")
decompressPath := filepath.Join(tmpdir, ".package-decompressed")
sbomPath := filepath.Join(tmpdir, ".sbom-location")

pkgName := fmt.Sprintf("zarf-package-variables-%s.tar.zst", e2e.Arch)

// Test that not specifying a package variable results in an error
_, stdErr, _ := e2e.Zarf("package", "create", "examples/variables", "--zarf-cache", cachePath, "--confirm")
_, stdErr, _ := e2e.Zarf("package", "create", "examples/variables", "--confirm")
expectedOutString := "variable 'NGINX_VERSION' must be '--set' when using the '--confirm' flag"
require.Contains(t, stdErr, "", expectedOutString)

// Test a simple package variable example with `--set` (will fail to pull an image if this is not set correctly)
stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/variables", "--set", "NGINX_VERSION=1.23.3", "--zarf-cache", cachePath, "--confirm")
stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/variables", "--set", "NGINX_VERSION=1.23.3", "--confirm")
require.NoError(t, err, stdOut, stdErr)

stdOut, stdErr, err = e2e.Zarf("t", "archiver", "decompress", pkgName, decompressPath, "--unarchive-all")
Expand Down
3 changes: 1 addition & 2 deletions src/test/e2e/06_create_sbom_test.go
Expand Up @@ -16,12 +16,11 @@ import (

func TestCreateSBOM(t *testing.T) {
tmpdir := t.TempDir()
cachePath := filepath.Join(tmpdir, ".cache-location")
sbomPath := filepath.Join(tmpdir, ".sbom-location")

pkgName := fmt.Sprintf("zarf-package-dos-games-%s-1.0.0.tar.zst", e2e.Arch)

stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/dos-games", "--zarf-cache", cachePath, "--sbom-out", sbomPath, "--confirm")
stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/dos-games", "--sbom-out", sbomPath, "--confirm")
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdErr, "Creating SBOMs for 1 images and 0 components with files.")
// Test that the game package generates the SBOMs we expect (images only)
Expand Down
7 changes: 3 additions & 4 deletions src/test/e2e/08_create_differential_test.go
Expand Up @@ -20,25 +20,24 @@ import (
func TestCreateDifferential(t *testing.T) {
t.Log("E2E: Test Differential Package Behavior")
tmpdir := t.TempDir()
cachePath := filepath.Join(tmpdir, ".cache-location")

packagePath := "src/test/packages/08-differential-package"
packageName := "zarf-package-differential-package-amd64-v0.25.0.tar.zst"
differentialPackageName := "zarf-package-differential-package-amd64-v0.25.0-differential-v0.26.0.tar.zst"
differentialFlag := fmt.Sprintf("--differential=%s", packageName)

// Build the package a first time
stdOut, stdErr, err := e2e.Zarf("package", "create", packagePath, "--zarf-cache", cachePath, "--set=PACKAGE_VERSION=v0.25.0", "--confirm")
stdOut, stdErr, err := e2e.Zarf("package", "create", packagePath, "--set=PACKAGE_VERSION=v0.25.0", "--confirm")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(packageName)

// Build the differential package without changing the version
_, stdErr, err = e2e.Zarf("package", "create", packagePath, "--zarf-cache", cachePath, "--set=PACKAGE_VERSION=v0.25.0", differentialFlag, "--confirm")
_, stdErr, err = e2e.Zarf("package", "create", packagePath, "--set=PACKAGE_VERSION=v0.25.0", differentialFlag, "--confirm")
require.Error(t, err, "zarf package create should have errored when a differential package was being created without updating the package version number")
require.Contains(t, stdErr, "unable to create a differential package with the same version")

// Build the differential package
stdOut, stdErr, err = e2e.Zarf("package", "create", packagePath, "--zarf-cache", cachePath, "--set=PACKAGE_VERSION=v0.26.0", differentialFlag, "--confirm")
stdOut, stdErr, err = e2e.Zarf("package", "create", packagePath, "--set=PACKAGE_VERSION=v0.26.0", differentialFlag, "--confirm")
require.NoError(t, err, stdOut, stdErr)
defer e2e.CleanFiles(differentialPackageName)

Expand Down
11 changes: 2 additions & 9 deletions src/test/e2e/09_component_compose_test.go
Expand Up @@ -25,7 +25,6 @@ var (
composeTest = filepath.Join("src", "test", "packages", "09-composable-packages")
composeTestPath string
composeTestBadLocalOS = filepath.Join("src", "test", "packages", "09-composable-packages", "bad-local-os")
relCacheDir string
)

func (suite *CompositionSuite) SetupSuite() {
Expand All @@ -34,25 +33,19 @@ func (suite *CompositionSuite) SetupSuite() {
// Setup the package paths after e2e has been initialized
composeExamplePath = filepath.Join("build", fmt.Sprintf("zarf-package-composable-packages-%s.tar.zst", e2e.Arch))
composeTestPath = filepath.Join("build", fmt.Sprintf("zarf-package-test-compose-package-%s.tar.zst", e2e.Arch))

// We make the cache dir relative to the working directory to make it work on the Windows Runners
// - they use two drives which filepath.Rel cannot cope with.
relCacheDir, _ = filepath.Abs(".cache-location")
}

func (suite *CompositionSuite) TearDownSuite() {
err := os.RemoveAll(composeExamplePath)
suite.NoError(err)
err = os.RemoveAll(composeTestPath)
suite.NoError(err)
err = os.RemoveAll(relCacheDir)
suite.NoError(err)
}

func (suite *CompositionSuite) Test_0_ComposabilityExample() {
suite.T().Log("E2E: Package Compose Example")

_, stdErr, err := e2e.Zarf("package", "create", composeExample, "-o", "build", "--zarf-cache", relCacheDir, "--no-color", "--confirm")
_, stdErr, err := e2e.Zarf("package", "create", composeExample, "-o", "build", "--no-color", "--confirm")
suite.NoError(err)

// Ensure that common names merge
Expand Down Expand Up @@ -190,7 +183,7 @@ func (suite *CompositionSuite) Test_1_FullComposability() {
func (suite *CompositionSuite) Test_2_ComposabilityBadLocalOS() {
suite.T().Log("E2E: Package Compose Example")

_, stdErr, err := e2e.Zarf("package", "create", composeTestBadLocalOS, "-o", "build", "--zarf-cache", relCacheDir, "--no-color", "--confirm")
_, stdErr, err := e2e.Zarf("package", "create", composeTestBadLocalOS, "-o", "build", "--no-color", "--confirm")
suite.Error(err)
suite.Contains(stdErr, "\"only.localOS\" \"linux\" cannot be\n redefined as \"windows\" during compose")
}
Expand Down
4 changes: 1 addition & 3 deletions src/test/e2e/22_git_and_gitops_test.go
Expand Up @@ -21,11 +21,9 @@ import (
func TestGit(t *testing.T) {
t.Log("E2E: Git")
e2e.SetupWithCluster(t)
tmpdir := t.TempDir()
cachePath := filepath.Join(tmpdir, ".cache-location")

buildPath := filepath.Join("src", "test", "packages", "22-git-data")
stdOut, stdErr, err := e2e.Zarf("package", "create", buildPath, "--zarf-cache", cachePath, "-o=build", "--confirm")
stdOut, stdErr, err := e2e.Zarf("package", "create", buildPath, "-o=build", "--confirm")
require.NoError(t, err, stdOut, stdErr)

path := fmt.Sprintf("build/zarf-package-git-data-test-%s-1.0.0.tar.zst", e2e.Arch)
Expand Down
6 changes: 2 additions & 4 deletions src/test/e2e/34_manifest_with_symlink_test.go
Expand Up @@ -14,19 +14,17 @@ import (

func TestManifestWithSymlink(t *testing.T) {
t.Log("E2E: Manifest With Symlink")
tmpdir := t.TempDir()
cachePath := filepath.Join(tmpdir, ".cache-location")

// Build the package, should succeed, even though there is a symlink in the package.
buildPath := filepath.Join("src", "test", "packages", "34-manifest-with-symlink")
stdOut, stdErr, err := e2e.Zarf("package", "create", buildPath, "--zarf-cache", cachePath, "-o=build", "--confirm")
stdOut, stdErr, err := e2e.Zarf("package", "create", buildPath, "-o=build", "--confirm")
require.NoError(t, err, stdOut, stdErr)

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)

stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--zarf-cache", cachePath, "--confirm")
stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--confirm")
defer e2e.CleanFiles("temp/manifests")
require.NoError(t, err, stdOut, stdErr)
require.FileExists(t, "temp/manifests/resources/img", "Symlink does not exist in the package as expected.")
Expand Down