forked from zarf-dev/zarf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move and test HasImages (zarf-dev#2831)
Signed-off-by: Philip Laine <philip.laine@gmail.com> Signed-off-by: Tim Seagren <timseagren@defenseunicorns.com>
- Loading branch information
1 parent
32ed1fe
commit bcc6a9e
Showing
3 changed files
with
112 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestZarfPackageIsInitPackage(t *testing.T) { | ||
t.Parallel() | ||
|
||
pkg := ZarfPackage{ | ||
Kind: ZarfInitConfig, | ||
} | ||
require.True(t, pkg.IsInitConfig()) | ||
pkg = ZarfPackage{ | ||
Kind: ZarfPackageConfig, | ||
} | ||
require.False(t, pkg.IsInitConfig()) | ||
} | ||
|
||
func TestZarfPackageHasImages(t *testing.T) { | ||
t.Parallel() | ||
|
||
pkg := ZarfPackage{ | ||
Components: []ZarfComponent{ | ||
{ | ||
Name: "without images", | ||
}, | ||
}, | ||
} | ||
require.False(t, pkg.HasImages()) | ||
pkg = ZarfPackage{ | ||
Components: []ZarfComponent{ | ||
{ | ||
Name: "with images", | ||
Images: []string{"docker.io/library/alpine:latest"}, | ||
}, | ||
}, | ||
} | ||
require.True(t, pkg.HasImages()) | ||
} | ||
|
||
func TestZarfPackageIsSBOMable(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
images []string | ||
files []ZarfFile | ||
dataInjections []ZarfDataInjection | ||
expected bool | ||
}{ | ||
{ | ||
name: "empty component", | ||
expected: false, | ||
}, | ||
{ | ||
name: "only images", | ||
images: []string{""}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "only files", | ||
files: []ZarfFile{{}}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "only data injections", | ||
dataInjections: []ZarfDataInjection{{}}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "all three set", | ||
images: []string{""}, | ||
files: []ZarfFile{{}}, | ||
dataInjections: []ZarfDataInjection{{}}, | ||
expected: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
pkg := ZarfPackage{ | ||
Components: []ZarfComponent{ | ||
{ | ||
Name: "without images", | ||
Images: tt.images, | ||
Files: tt.files, | ||
DataInjections: tt.dataInjections, | ||
}, | ||
}, | ||
} | ||
require.Equal(t, tt.expected, pkg.IsSBOMAble()) | ||
}) | ||
} | ||
} |