Skip to content

Commit

Permalink
feat(test): add test for remote
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtkeller committed Feb 13, 2025
1 parent e24ea34 commit 71bff83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
50 changes: 33 additions & 17 deletions src/internal/packager2/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package packager2

import (
"context"
"os"
"testing"

goyaml "github.com/goccy/go-yaml"
"github.com/stretchr/testify/require"
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/pkg/zoci"
"github.com/zarf-dev/zarf/src/test/testutil"
"oras.land/oras-go/v2/registry"
)
Expand All @@ -20,43 +24,55 @@ func TestPublish(t *testing.T) {
}

tt := []struct {
name string
opts PublishOpts
expect bool
name string
opts PublishOpts
expectErr bool
}{
{
name: "Test empty publishopts",
opts: PublishOpts{},
expect: true,
name: "Test empty publishopts",
opts: PublishOpts{},
expectErr: true,
},
{
name: "Test empty path",
opts: PublishOpts{
Path: "",
Registry: ref,
},
expect: true,
expectErr: true,
},
{
name: "Publish skeleton package",
opts: PublishOpts{
Path: "testdata/skeleton",
Registry: ref,
},
expectErr: true,
},
// {
// name: "publish skeleton package",
// opts: PublishOpts{
// Path: "testdata/skeleton",
// Registry: ref,
// },
// expect: "",
// },
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
// TODO Make parallel
// t.Parallel()
err := Publish(context.Background(), tc.opts)
if tc.expect {
if tc.expectErr {
require.Error(t, err)
}

// TODO: Read manifest from registry
rmt, err := zoci.NewRemote(ctx, tc.opts.Registry.Reference, zoci.PlatformForSkeleton())
require.NoError(t, err)

pkg, err := rmt.FetchZarfYAML(ctx)
require.NoError(t, err)

data, err := os.ReadFile(tc.opts.Path)
require.NoError(t, err)

var expectedPkg v1alpha1.ZarfPackage
goyaml.Unmarshal(data, &expectedPkg)

require.Equal(t, pkg, expectedPkg)

// TODO: check sha of the resulting publish
// err := oras.PackManifest()
Expand Down
3 changes: 0 additions & 3 deletions src/internal/packager2/testdata/skeleton/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ metadata:
components:
- name: on-deploy-with-template-use-of-variable
required: true
files:
- source: test.txt
target: test.txt

0 comments on commit 71bff83

Please sign in to comment.