Skip to content

Commit

Permalink
simplify test
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Feb 24, 2025
1 parent dacab37 commit b79e090
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
35 changes: 22 additions & 13 deletions src/internal/packager2/layout/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/stretchr/testify/require"

"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/config"
"github.com/zarf-dev/zarf/src/pkg/layout"
"github.com/zarf-dev/zarf/src/pkg/lint"
"github.com/zarf-dev/zarf/src/test/testutil"
Expand Down Expand Up @@ -228,15 +227,34 @@ func TestLoadPackageErrorWithoutCompatibleFlavor(t *testing.T) {
require.EqualError(t, err, fmt.Sprintf("package validation failed: %s", lint.PkgValidateErrNoComponents))
}

func writePackageToDisk(t *testing.T, pkg v1alpha1.ZarfPackage, dir string) {
t.Helper()
b, err := goyaml.Marshal(pkg)
require.NoError(t, err)
path := filepath.Join(dir, ZarfYAML)
err = os.WriteFile(path, b, 0700)
require.NoError(t, err)
}

func TestGetSBOM(t *testing.T) {
t.Parallel()
lint.ZarfSchema = testutil.LoadSchema(t, "../../../../zarf.schema.json")

tmpdir := t.TempDir()
packageDefinitionPath := filepath.Join("testdata", "non-sbom-package")
config.CommonOptions.TempDirectory = tmpdir
pkg := v1alpha1.ZarfPackage{
Kind: v1alpha1.ZarfPackageConfig,
Metadata: v1alpha1.ZarfMetadata{
Name: "test-sbom",
},
Components: []v1alpha1.ZarfComponent{
{
Name: "do-nothing",
},
},
}
writePackageToDisk(t, pkg, tmpdir)

pkgLayout, err := CreatePackage(context.Background(), packageDefinitionPath, CreateOptions{})
pkgLayout, err := CreatePackage(context.Background(), tmpdir, CreateOptions{})
require.NoError(t, err)

// Ensure the SBOM does not exist
Expand All @@ -259,15 +277,6 @@ func TestCreateAbsolutePathFileSource(t *testing.T) {
return absoluteFilePath
}

writePackageToDisk := func(t *testing.T, pkg v1alpha1.ZarfPackage, dir string) {
t.Helper()
b, err := goyaml.Marshal(pkg)
require.NoError(t, err)
path := filepath.Join(dir, "zarf.yaml")
err = os.WriteFile(path, b, 0700)
require.NoError(t, err)
}

t.Run("test a standard package can use absolute file paths", func(t *testing.T) {
t.Parallel()
tmpdir := t.TempDir()
Expand Down

This file was deleted.

0 comments on commit b79e090

Please sign in to comment.