-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf4ffda
commit c162532
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |