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

fix: differential package create with non local sources #2444

Merged
merged 4 commits into from
Apr 18, 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
12 changes: 8 additions & 4 deletions src/pkg/packager/creator/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +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) {
createOpts.DifferentialPackagePath = filepath.Join(cwd, createOpts.DifferentialPackagePath)
func updateRelativeDifferentialPackagePath(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 = updateRelativeDifferentialPackagePath(createOpts.DifferentialPackagePath, cwd)
return &PackageCreator{createOpts, cfg}
}

Expand Down
58 changes: 58 additions & 0 deletions src/pkg/packager/creator/normal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package creator contains functions for creating Zarf packages.
package creator

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestDifferentialPackagePathSetCorrectly(t *testing.T) {
type testCase struct {
name string
path string
cwd string
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: filepath.Join("home", "cool-guy", "zarf-package"),
expected: filepath.Join("home", "cool-guy", "zarf-package", "my-package.tar.zst"),
},
{
name: "absolute path",
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: 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: 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))
})
}
}