Skip to content

Commit

Permalink
test: clean up tests for composer
Browse files Browse the repository at this point in the history
  • Loading branch information
phillebaba committed May 23, 2024
1 parent 0ec9139 commit 0870d9d
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/pkg/packager/composer/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ func TestNewImportChain(t *testing.T) {
t.Parallel()

tests := []struct {
name string
head types.ZarfComponent
arch string
flavor string
expectedErrorMessage string
name string
head types.ZarfComponent
arch string
flavor string
expectedErr string
}{
{
name: "No Architecture",
head: types.ZarfComponent{},
expectedErrorMessage: "architecture must be provided",
name: "No Architecture",
head: types.ZarfComponent{},
expectedErr: "architecture must be provided",
},
{
name: "Circular Import",
Expand All @@ -38,8 +38,8 @@ func TestNewImportChain(t *testing.T) {
Path: ".",
},
},
arch: "amd64",
expectedErrorMessage: "detected circular import chain",
arch: "amd64",
expectedErr: "detected circular import chain",
},
}
testPackageName := "test-package"
Expand All @@ -49,7 +49,7 @@ func TestNewImportChain(t *testing.T) {
t.Parallel()

_, err := NewImportChain(tt.head, 0, testPackageName, tt.arch, tt.flavor)
require.Contains(t, err.Error(), tt.expectedErrorMessage)
require.ErrorContains(t, err, tt.expectedErr)
})
}
}
Expand All @@ -66,11 +66,9 @@ func TestCompose(t *testing.T) {
firstDirectoryActionDefault := "hello-dc"

tests := []struct {
name string
ic *ImportChain
returnError bool
expectedComposed types.ZarfComponent
expectedErrorMessage string
name string
ic *ImportChain
expectedComposed types.ZarfComponent
}{
{
name: "Single Component",
Expand All @@ -79,7 +77,6 @@ func TestCompose(t *testing.T) {
Name: "no-import",
},
}),
returnError: false,
expectedComposed: types.ZarfComponent{
Name: "no-import",
},
Expand All @@ -91,7 +88,6 @@ func TestCompose(t *testing.T) {
createDummyComponent(t, "world", secondDirectory, "world"),
createDummyComponent(t, "today", "", "hello"),
}),
returnError: false,
expectedComposed: types.ZarfComponent{
Name: "import-hello",
// Files should always be appended with corrected directories
Expand Down Expand Up @@ -238,18 +234,14 @@ func TestCompose(t *testing.T) {
},
},
}

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

composed, err := tt.ic.Compose()
if tt.returnError {
require.Contains(t, err.Error(), tt.expectedErrorMessage)
} else {
require.EqualValues(t, &tt.expectedComposed, composed)
}
require.NoError(t, err)
require.EqualValues(t, &tt.expectedComposed, composed)
})
}
}
Expand Down

0 comments on commit 0870d9d

Please sign in to comment.