-
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.
test: add tests for FindImages (#2850)
Signed-off-by: Philip Laine <[email protected]>
- Loading branch information
1 parent
95e9e45
commit 447d984
Showing
5 changed files
with
86 additions
and
25 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,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
package packager | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zarf-dev/zarf/src/pkg/lint" | ||
"github.com/zarf-dev/zarf/src/test/testutil" | ||
"github.com/zarf-dev/zarf/src/types" | ||
) | ||
|
||
func TestFindImages(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := testutil.TestContext(t) | ||
|
||
lint.ZarfSchema = testutil.LoadSchema(t, "../../../zarf.schema.json") | ||
|
||
cfg := &types.PackagerConfig{ | ||
CreateOpts: types.ZarfCreateOptions{ | ||
BaseDir: "../../../examples/dos-games/", | ||
}, | ||
} | ||
p, err := New(cfg) | ||
require.NoError(t, err) | ||
images, err := p.FindImages(ctx) | ||
require.NoError(t, err) | ||
expectedImages := map[string][]string{ | ||
"baseline": { | ||
"defenseunicorns/zarf-game:multi-tile-dark", | ||
"index.docker.io/defenseunicorns/zarf-game:sha256-0b694ca1c33afae97b7471488e07968599f1d2470c629f76af67145ca64428af.sig", | ||
}, | ||
} | ||
require.Equal(t, len(expectedImages), len(images)) | ||
for k, v := range expectedImages { | ||
require.ElementsMatch(t, v, images[k]) | ||
} | ||
} |
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,33 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
package testutil | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type schemaFS struct { | ||
b []byte | ||
} | ||
|
||
func (m *schemaFS) ReadFile(_ string) ([]byte, error) { | ||
return m.b, nil | ||
} | ||
|
||
func (m *schemaFS) Open(_ string) (fs.File, error) { | ||
return nil, nil | ||
} | ||
|
||
// LoadSchema returns the schema file as a FS. | ||
func LoadSchema(t *testing.T, path string) fs.ReadFileFS { | ||
t.Helper() | ||
|
||
b, err := os.ReadFile(path) | ||
require.NoError(t, err) | ||
return &schemaFS{b: b} | ||
} |
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