diff --git a/src/internal/packager2/publish_test.go b/src/internal/packager2/publish_test.go index d6c22014af..fe82ec84d1 100644 --- a/src/internal/packager2/publish_test.go +++ b/src/internal/packager2/publish_test.go @@ -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" ) @@ -20,14 +24,14 @@ 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", @@ -35,16 +39,16 @@ func TestPublish(t *testing.T) { 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 { @@ -52,11 +56,23 @@ func TestPublish(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() diff --git a/src/internal/packager2/testdata/skeleton/zarf.yaml b/src/internal/packager2/testdata/skeleton/zarf.yaml index 86038ec3df..86af735e00 100644 --- a/src/internal/packager2/testdata/skeleton/zarf.yaml +++ b/src/internal/packager2/testdata/skeleton/zarf.yaml @@ -7,6 +7,3 @@ metadata: components: - name: on-deploy-with-template-use-of-variable required: true - files: - - source: test.txt - target: test.txt