package cmp_test import ( "fmt" "testing" "github.com/stretchr/testify/assert" "edge-infra.dev/pkg/f8n/warehouse/oci" "edge-infra.dev/pkg/f8n/warehouse/oci/cmp" ) func TestDiff(t *testing.T) { t.Parallel() tcs := []struct { a oci.Artifact bb []oci.Artifact }{ {shoot, []oci.Artifact{shoot}}, {shoot, []oci.Artifact{ redpanda, certmgr, store, chirp, patchmanager, prometheus, }}, {shoot, []oci.Artifact{ ctlfish, edgeIAM, novnc, couchdb, fluentbit, ksm, corednsctl, }}, {shoot, []oci.Artifact{store}}, {shoot, []oci.Artifact{fluentbit, prometheus, certmgr, redpanda}}, {shoot, []oci.Artifact{ redpanda, certmgr, store, chirp, patchmanager, prometheus, ctlfish, edgeIAM, novnc, couchdb, fluentbit, ksm, corednsctl, }}, {shoot, []oci.Artifact{}}, {certmgr, []oci.Artifact{certmgr}}, {certmgr, []oci.Artifact{ redpanda, store, chirp, patchmanager, prometheus, }}, {certmgr, []oci.Artifact{ ctlfish, edgeIAM, novnc, couchdb, fluentbit, ksm, corednsctl, }}, {certmgr, []oci.Artifact{store}}, {certmgr, []oci.Artifact{}}, {certmgr, []oci.Artifact{fluentbit, prometheus, redpanda}}, {certmgr, []oci.Artifact{ redpanda, store, chirp, patchmanager, prometheus, ctlfish, edgeIAM, novnc, couchdb, fluentbit, ksm, corednsctl, }}, {store, []oci.Artifact{store}}, {certmgr, []oci.Artifact{}}, {certmgr, nil}, {store, []oci.Artifact{ redpanda, certmgr, store, chirp, patchmanager, prometheus, }}, {store, []oci.Artifact{ ctlfish, edgeIAM, novnc, couchdb, fluentbit, ksm, corednsctl, }}, {store, []oci.Artifact{shoot}}, {store, []oci.Artifact{fluentbit, prometheus, certmgr, redpanda}}, {store, []oci.Artifact{ redpanda, certmgr, store, chirp, patchmanager, prometheus, ctlfish, edgeIAM, novnc, couchdb, fluentbit, ksm, corednsctl, }}, } for i, tc := range tcs { tc := tc i := i t.Run(fmt.Sprintf("%s-%d", t.Name(), i), func(t *testing.T) { t.Parallel() a := assert.New(t) hashes, err := cmp.Hashes(tc.a) a.NoError(err) t.Log("hashes in artifact", hashes) diff, err := cmp.Diff(tc.a, tc.bb...) a.NoError(err) t.Log("calculated diff", diff) // If we diff against ourselves, should be empty if len(tc.bb) == 1 && tc.a == tc.bb[0] { a.Len(diff, 0) } if len(tc.bb) == 0 { t.Log("diffing against empty set of artifacts") a.Len(diff, len(hashes)) // Every hash in a should be in result for _, h := range hashes { found := false for _, d := range diff { if d == h { found = true break } } a.True(found, "digest %s not present in diff", h.Hex) } } for _, d := range diff { found, err := cmp.ContainsBlob(d, tc.bb...) a.NoError(err) a.False(found, "digest %s in diff but found in bb", d.Hex) found, err = cmp.ContainsBlob(d, tc.a) a.NoError(err) a.True(found, "digest %s in diff but not found in a", d.Hex) } }) } }