Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Jul 4, 2024
1 parent 4706e15 commit 9b0dcfe
Showing 1 changed file with 102 additions and 22 deletions.
124 changes: 102 additions & 22 deletions attest/vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ import (
. "github.com/onsi/gomega"

. "github.com/errordeveloper/tape/attest"
"github.com/errordeveloper/tape/attest/vcs/git"
"github.com/errordeveloper/tape/manifest/imagescanner"
"github.com/errordeveloper/tape/manifest/loader"
"github.com/errordeveloper/tape/oci"
)

type vcsTestCase struct {
URL string
CheckoutTag string
CheckoutHash string
Branch string
LoadPath string
ExpectTags []string
URL, CheckoutTag, CheckoutHash, Branch string
LoadPath string
ExpectManifests, ExpectImageTags, ExpectRawTags []string
}

func (tc vcsTestCase) Name() string {
Expand All @@ -40,25 +38,94 @@ func (tc vcsTestCase) Name() string {
func TestVCS(t *testing.T) {
testCases := []vcsTestCase{
{
URL: "https://github.com/stefanprodan/podinfo",
CheckoutTag: "6.7.0", // => 0b1481aa8ed0a6c34af84f779824a74200d5c1d6
LoadPath: "kustomize",
ExpectTags: []string{"6.7.0"},
URL: "https://github.com/stefanprodan/podinfo",
CheckoutTag: "6.7.0", // => 0b1481aa8ed0a6c34af84f779824a74200d5c1d6
LoadPath: "kustomize",
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
ExpectImageTags: []string{"6.7.0"},
ExpectRawTags: []string{"6.7.0"},
},
{
URL: "https://github.com/stefanprodan/podinfo",
CheckoutHash: "0b1481aa8ed0a6c34af84f779824a74200d5c1d6", // => 6.7.0
Branch: "master",
LoadPath: "kustomize",
ExpectTags: []string{"6.7.0"},
URL: "https://github.com/stefanprodan/podinfo",
CheckoutHash: "0b1481aa8ed0a6c34af84f779824a74200d5c1d6", // => 6.7.0
Branch: "master",
LoadPath: "kustomize",
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
ExpectImageTags: []string{"6.7.0"},
ExpectRawTags: []string{"6.7.0"},
},
{
URL: "https://github.com/stefanprodan/podinfo",
CheckoutHash: "ba6f4ffd7cba98ea2ef52bee7c1bead8e1d6a7d3", // pre-6.7.0
Branch: "master",
LoadPath: "kustomize",
ExpectTags: nil,
URL: "https://github.com/stefanprodan/podinfo",
CheckoutHash: "ba6f4ffd7cba98ea2ef52bee7c1bead8e1d6a7d3", // pre-6.7.0
Branch: "master",
LoadPath: "kustomize",
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
ExpectImageTags: nil,
ExpectRawTags: nil,
},
{
URL: "https://github.com/stefanprodan/podinfo",
CheckoutTag: "6.6.1",
Branch: "master",
LoadPath: "kustomize",
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
ExpectImageTags: []string{"6.6.1"},
ExpectRawTags: []string{"6.6.1"},
},
{
URL: "https://github.com/stefanprodan/podinfo",
CheckoutTag: "6.6.2",
Branch: "master",
LoadPath: "",
ExpectManifests: []string{"kustomize/kustomization.yaml", "kustomize/deployment.yaml", "kustomize/hpa.yaml", "kustomize/service.yaml"},
ExpectImageTags: []string{"6.6.1"},
ExpectRawTags: []string{"6.6.1"},
},
{
URL: "https://github.com/fluxcd/pkg",
CheckoutHash: "c647aea83012218c0353d3408b2237bb639578f3",
Branch: "master",
LoadPath: "version",
ExpectImageTags: nil,
ExpectRawTags: nil,
},
// {
// URL: "https://github.com/fluxcd/pkg",
// CheckoutTag: "version/v0.4.0",
// Branch: "master",
// LoadPath: "version",
// ExpectImageTags: nil, // TODO: should be 0.4.0
// ExpectRawTags: []string{
// "version/v0.4.0",
// "testserver/v0.7.0",
// "tar/v0.7.0",
// "ssh/v0.13.0",
// "ssa/v0.39.1",
// "ssa/v0.39.0",
// "sourceignore/v0.7.0",
// "runtime/v0.47.1",
// "runtime/v0.47.0",
// "oci/v0.38.1",
// "oci/v0.38.0",
// "oci/v0.37.1",
// "oci/v0.37.0",
// "masktoken/v0.4.0",
// "lockedfile/v0.3.0",
// "kustomize/v1.11.0",
// "http/transport/v0.3.0",
// "http/fetch/v0.11.0",
// "helmtestserver/v0.18.0",
// "gittestserver/v0.12.0",
// "git/v0.19.0",
// "git/gogit/v0.19.0",
// "envsubst/v1.1.0",
// "cache/v0.0.1",
// "apis/meta/v1.5.0",
// "apis/kustomize/v1.5.0",
// "apis/event/v0.9.0",
// "apis/acl/v0.3.0",
// },
// },
}

repos := &repos{}
Expand Down Expand Up @@ -90,7 +157,9 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
scanner := imagescanner.NewDefaultImageScanner()
scanner.WithProvinanceAttestor(attreg)

g.Expect(loader.Paths()).To(HaveLen(4))
if tc.ExpectManifests != nil {
g.Expect(loader.Paths()).To(ConsistOf(tc.ExpectManifests))
}

g.Expect(scanner.Scan(loader.RelPaths())).To(Succeed())

Expand All @@ -115,12 +184,23 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {

// TODO: validate schema

groupSummary, ok := vcsSummary.Full().(*git.Summary)
g.Expect(ok).To(BeTrue())
ref := groupSummary.Git.Reference
g.Expect(ref.Tags).To(HaveLen(len(tc.ExpectRawTags)))
for i, tag := range tc.ExpectRawTags {
g.Expect(ref.Tags[i].Name).To(Equal(tag))
}

image, err := name.NewRepository("podinfo")
g.Expect(err).NotTo(HaveOccurred())

semVerTags := oci.SemVerTagsFromAttestations(ctx, image.Tag("test.123456"), statements...)

g.Expect(semVerTags).To(HaveLen(len(tc.ExpectTags)))
g.Expect(semVerTags).To(HaveLen(len(tc.ExpectImageTags)))
for i, tag := range tc.ExpectImageTags {
g.Expect(semVerTags[i].TagStr()).To(Equal(tag))
}
}
}

Expand Down

0 comments on commit 9b0dcfe

Please sign in to comment.