-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add unit tests for creator.LoadPackageDefinition (#2531)
Relates to #2512
- Loading branch information
Lucas Rodriguez
authored
May 22, 2024
1 parent
b8dd1bb
commit 21995e9
Showing
9 changed files
with
128 additions
and
12 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
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
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
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
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
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,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 ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/defenseunicorns/zarf/src/pkg/layout" | ||
"github.com/defenseunicorns/zarf/src/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSkeletonLoadPackageDefinition(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)) | ||
sc := NewSkeletonCreator(types.ZarfCreateOptions{}, types.ZarfPublishOptions{}) | ||
pkg, _, err := sc.LoadPackageDefinition(src) | ||
|
||
if tt.expectedErr == "" { | ||
require.NoError(t, err) | ||
require.NotEmpty(t, pkg) | ||
return | ||
} | ||
|
||
require.EqualError(t, err, tt.expectedErr) | ||
require.Empty(t, pkg) | ||
}) | ||
} | ||
} |
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,4 @@ | ||
kind: ZarfPackageConfig | ||
metadata: | ||
name: minimal-invalid | ||
description: Must have at least 1 component |
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,6 @@ | ||
kind: ZarfPackageConfig | ||
metadata: | ||
name: minimal-valid | ||
description: Minimal valid package | ||
components: | ||
- name: component1 |
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