From dcdad6f052a414c202583ccac29e8ab72f9d885c Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 18 Apr 2024 14:20:35 +0000 Subject: [PATCH 1/4] fix differential-oci --- src/pkg/packager/creator/normal.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 5693d32d98..5c6aaee9fc 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -50,7 +50,9 @@ type PackageCreator struct { // NewPackageCreator returns a new PackageCreator. func NewPackageCreator(createOpts types.ZarfCreateOptions, cfg *types.PackagerConfig, cwd string) *PackageCreator { - if createOpts.DifferentialPackagePath != "" && !filepath.IsAbs(createOpts.DifferentialPackagePath) { + if createOpts.DifferentialPackagePath != "" && + !filepath.IsAbs(createOpts.DifferentialPackagePath) && + !helpers.IsURL(createOpts.DifferentialPackagePath) { createOpts.DifferentialPackagePath = filepath.Join(cwd, createOpts.DifferentialPackagePath) } From fbdfeacb273e374fd160b6479bd084315647c202 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 18 Apr 2024 15:18:35 +0000 Subject: [PATCH 2/4] testing --- src/pkg/packager/creator/normal.go | 14 ++++--- src/pkg/packager/creator/normal_test.go | 55 +++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 src/pkg/packager/creator/normal_test.go diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 5c6aaee9fc..045f6175d6 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -48,14 +48,16 @@ type PackageCreator struct { cfg *types.PackagerConfig } -// NewPackageCreator returns a new PackageCreator. -func NewPackageCreator(createOpts types.ZarfCreateOptions, cfg *types.PackagerConfig, cwd string) *PackageCreator { - if createOpts.DifferentialPackagePath != "" && - !filepath.IsAbs(createOpts.DifferentialPackagePath) && - !helpers.IsURL(createOpts.DifferentialPackagePath) { - createOpts.DifferentialPackagePath = filepath.Join(cwd, createOpts.DifferentialPackagePath) +func localizeDifferentialPackagePath(path string, cwd string) string { + if path != "" && !filepath.IsAbs(path) && !helpers.IsURL(path) { + return filepath.Join(cwd, path) } + return path +} +// NewPackageCreator returns a new PackageCreator. +func NewPackageCreator(createOpts types.ZarfCreateOptions, cfg *types.PackagerConfig, cwd string) *PackageCreator { + createOpts.DifferentialPackagePath = localizeDifferentialPackagePath(createOpts.DifferentialPackagePath, cwd) return &PackageCreator{createOpts, cfg} } diff --git a/src/pkg/packager/creator/normal_test.go b/src/pkg/packager/creator/normal_test.go new file mode 100644 index 0000000000..e1f81ca3ec --- /dev/null +++ b/src/pkg/packager/creator/normal_test.go @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package creator contains functions for creating Zarf packages. +package creator + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNewImportChain(t *testing.T) { + type testCase struct { + name string + path string + cwd string + expected string + } + + testCases := []testCase{ + { + name: "relative path", + path: "my-package.tar.zst", + cwd: "/home/cool-guy/zarf-package", + expected: "/home/cool-guy/zarf-package/my-package.tar.zst", + }, + { + name: "absolute path", + path: "/home/cool-guy/zarf-package/my-package.tar.zst", + cwd: "/home/cool-guy/zarf-package", + expected: "/home/cool-guy/zarf-package/my-package.tar.zst", + }, + { + name: "oci path", + path: "oci://my-cool-registry.com:555/my-package.tar.zst", + cwd: "/home/cool-guy/zarf-package", + expected: "oci://my-cool-registry.com:555/my-package.tar.zst", + }, + { + name: "https path", + path: "https://neat-url.com/zarf-init-amd64-v1.0.0.tar.zst", + cwd: "/home/cool-guy/zarf-package", + expected: "https://neat-url.com/zarf-init-amd64-v1.0.0.tar.zst", + }, + } + for _, testCase := range testCases { + tc := testCase + + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + require.Equal(t, tc.expected, localizeDifferentialPackagePath(tc.path, tc.cwd)) + }) + } +} From 5e14aedc1ae545c1ab876798cefe3864dfa6e5cb Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 18 Apr 2024 15:20:17 +0000 Subject: [PATCH 3/4] naming --- src/pkg/packager/creator/normal.go | 4 ++-- src/pkg/packager/creator/normal_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 045f6175d6..e9904852f2 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -48,7 +48,7 @@ type PackageCreator struct { cfg *types.PackagerConfig } -func localizeDifferentialPackagePath(path string, cwd string) string { +func updateRelativeDifferentialPackagePath(path string, cwd string) string { if path != "" && !filepath.IsAbs(path) && !helpers.IsURL(path) { return filepath.Join(cwd, path) } @@ -57,7 +57,7 @@ func localizeDifferentialPackagePath(path string, cwd string) string { // NewPackageCreator returns a new PackageCreator. func NewPackageCreator(createOpts types.ZarfCreateOptions, cfg *types.PackagerConfig, cwd string) *PackageCreator { - createOpts.DifferentialPackagePath = localizeDifferentialPackagePath(createOpts.DifferentialPackagePath, cwd) + createOpts.DifferentialPackagePath = updateRelativeDifferentialPackagePath(createOpts.DifferentialPackagePath, cwd) return &PackageCreator{createOpts, cfg} } diff --git a/src/pkg/packager/creator/normal_test.go b/src/pkg/packager/creator/normal_test.go index e1f81ca3ec..c07ee666ba 100644 --- a/src/pkg/packager/creator/normal_test.go +++ b/src/pkg/packager/creator/normal_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestNewImportChain(t *testing.T) { +func TestDifferentialPackagePathSetCorrectly(t *testing.T) { type testCase struct { name string path string @@ -49,7 +49,7 @@ func TestNewImportChain(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() - require.Equal(t, tc.expected, localizeDifferentialPackagePath(tc.path, tc.cwd)) + require.Equal(t, tc.expected, updateRelativeDifferentialPackagePath(tc.path, tc.cwd)) }) } } From 0c46cd039113d4e35c108c1b64c8c89332222b35 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 18 Apr 2024 15:58:32 +0000 Subject: [PATCH 4/4] fix tests for windows --- src/pkg/packager/creator/normal_test.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pkg/packager/creator/normal_test.go b/src/pkg/packager/creator/normal_test.go index c07ee666ba..9a4830cb1f 100644 --- a/src/pkg/packager/creator/normal_test.go +++ b/src/pkg/packager/creator/normal_test.go @@ -5,6 +5,7 @@ package creator import ( + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -18,35 +19,37 @@ func TestDifferentialPackagePathSetCorrectly(t *testing.T) { expected string } + absolutePackagePath, err := filepath.Abs(filepath.Join("home", "cool-guy", "zarf-package", "my-package.tar.zst")) + require.NoError(t, err) + testCases := []testCase{ { name: "relative path", path: "my-package.tar.zst", - cwd: "/home/cool-guy/zarf-package", - expected: "/home/cool-guy/zarf-package/my-package.tar.zst", + cwd: filepath.Join("home", "cool-guy", "zarf-package"), + expected: filepath.Join("home", "cool-guy", "zarf-package", "my-package.tar.zst"), }, { name: "absolute path", - path: "/home/cool-guy/zarf-package/my-package.tar.zst", - cwd: "/home/cool-guy/zarf-package", - expected: "/home/cool-guy/zarf-package/my-package.tar.zst", + path: absolutePackagePath, + cwd: filepath.Join("home", "should-not-matter"), + expected: absolutePackagePath, }, { name: "oci path", path: "oci://my-cool-registry.com:555/my-package.tar.zst", - cwd: "/home/cool-guy/zarf-package", + cwd: filepath.Join("home", "should-not-matter"), expected: "oci://my-cool-registry.com:555/my-package.tar.zst", }, { name: "https path", path: "https://neat-url.com/zarf-init-amd64-v1.0.0.tar.zst", - cwd: "/home/cool-guy/zarf-package", + cwd: filepath.Join("home", "should-not-matter"), expected: "https://neat-url.com/zarf-init-amd64-v1.0.0.tar.zst", }, } for _, testCase := range testCases { tc := testCase - t.Run(tc.name, func(t *testing.T) { t.Parallel() require.Equal(t, tc.expected, updateRelativeDifferentialPackagePath(tc.path, tc.cwd))