Skip to content

Commit

Permalink
refactor creator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinAbro321 committed Jun 24, 2024
1 parent cf4ffda commit c162532
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/pkg/packager/creator/creator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package creator contains functions for creating Zarf packages.
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"
)

func TestLoadPackageDefinitionWithValidate(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{}),
},
}

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

src := layout.New(filepath.Join("testdata", tt.testDir))
pkg, _, err := tt.creator.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)
})
}
}

0 comments on commit c162532

Please sign in to comment.