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

test: move creator tests into one file #2658

Merged
merged 1 commit into from
Jun 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,37 @@ import (
"github.com/stretchr/testify/require"
)

func TestSkeletonLoadPackageDefinition(t *testing.T) {
func TestLoadPackageDefinition(t *testing.T) {
t.Parallel()

tests := []struct {
name string
testDir string
expectedErr string
creator Creator
}{
{
name: "valid package definition",
testDir: "valid",
expectedErr: "",
creator: NewPackageCreator(types.ZarfCreateOptions{}, ""),
},
{
name: "invalid package definition",
testDir: "invalid",
expectedErr: "package must have at least 1 component",
creator: NewPackageCreator(types.ZarfCreateOptions{}, ""),
},
{
name: "valid package definition",
testDir: "valid",
expectedErr: "",
creator: NewSkeletonCreator(types.ZarfCreateOptions{}, types.ZarfPublishOptions{}),
},
{
name: "invalid package definition",
testDir: "invalid",
expectedErr: "package must have at least 1 component",
creator: NewSkeletonCreator(types.ZarfCreateOptions{}, types.ZarfPublishOptions{}),
},
}

Expand All @@ -40,8 +54,7 @@ func TestSkeletonLoadPackageDefinition(t *testing.T) {
t.Parallel()

src := layout.New(filepath.Join("testdata", tt.testDir))
sc := NewSkeletonCreator(types.ZarfCreateOptions{}, types.ZarfPublishOptions{})
pkg, _, err := sc.LoadPackageDefinition(context.Background(), src)
pkg, _, err := tt.creator.LoadPackageDefinition(context.Background(), src)

if tt.expectedErr == "" {
require.NoError(t, err)
Expand Down
44 changes: 0 additions & 44 deletions src/pkg/packager/creator/normal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
package creator

import (
"context"
"path/filepath"
"testing"

"github.com/defenseunicorns/zarf/src/pkg/layout"
"github.com/defenseunicorns/zarf/src/types"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -59,44 +56,3 @@ func TestDifferentialPackagePathSetCorrectly(t *testing.T) {
})
}
}

func TestLoadPackageDefinition(t *testing.T) {
t.Parallel()

tests := []struct {
name string
testDir string
expectedErr string
}{
{
name: "valid package definition",
testDir: "valid",
expectedErr: "",
},
{
name: "invalid package definition",
testDir: "invalid",
expectedErr: "package must have at least 1 component",
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

src := layout.New(filepath.Join("testdata", tt.testDir))
pc := NewPackageCreator(types.ZarfCreateOptions{}, "")
pkg, _, err := pc.LoadPackageDefinition(context.Background(), src)

if tt.expectedErr == "" {
require.NoError(t, err)
require.NotEmpty(t, pkg)
return
}

require.EqualError(t, err, tt.expectedErr)
require.Empty(t, pkg)
})
}
}
Loading