Skip to content

Commit 1f9ef7b

Browse files
WIP
1 parent bc33eba commit 1f9ef7b

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

attest/vcs_test.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import (
1010

1111
gogit "github.com/go-git/go-git/v5"
1212
"github.com/go-git/go-git/v5/plumbing"
13+
"github.com/google/go-containerregistry/pkg/name"
1314

1415
. "github.com/onsi/gomega"
1516

1617
. "github.com/errordeveloper/tape/attest"
1718
"github.com/errordeveloper/tape/manifest/imagescanner"
1819
"github.com/errordeveloper/tape/manifest/loader"
20+
"github.com/errordeveloper/tape/oci"
1921
)
2022

2123
type vcsTestCase struct {
@@ -24,6 +26,7 @@ type vcsTestCase struct {
2426
CheckoutHash string
2527
Branch string
2628
LoadPath string
29+
ExpectTags []string
2730
}
2831

2932
func (tc vcsTestCase) Name() string {
@@ -40,12 +43,21 @@ func TestVCS(t *testing.T) {
4043
URL: "https://github.com/stefanprodan/podinfo",
4144
CheckoutTag: "6.7.0", // => 0b1481aa8ed0a6c34af84f779824a74200d5c1d6
4245
LoadPath: "kustomize",
46+
ExpectTags: []string{"6.7.0"},
4347
},
4448
{
4549
URL: "https://github.com/stefanprodan/podinfo",
4650
CheckoutHash: "0b1481aa8ed0a6c34af84f779824a74200d5c1d6", // => 6.7.0
4751
Branch: "master",
4852
LoadPath: "kustomize",
53+
ExpectTags: []string{"6.7.0"},
54+
},
55+
{
56+
URL: "https://github.com/stefanprodan/podinfo",
57+
CheckoutHash: "ba6f4ffd7cba98ea2ef52bee7c1bead8e1d6a7d3", // pre-6.7.0
58+
Branch: "master",
59+
LoadPath: "kustomize",
60+
ExpectTags: nil,
4961
},
5062
}
5163

@@ -62,7 +74,8 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
6274
return func(t *testing.T) {
6375
g := NewWithT(t)
6476

65-
checkoutPath, err := repos.clone(context.Background(), tc)
77+
ctx := context.Background()
78+
checkoutPath, err := repos.clone(ctx, tc)
6679
g.Expect(err).NotTo(HaveOccurred())
6780

6881
loadPath := filepath.Join(checkoutPath, tc.LoadPath)
@@ -77,14 +90,37 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
7790
scanner := imagescanner.NewDefaultImageScanner()
7891
scanner.WithProvinanceAttestor(attreg)
7992

93+
g.Expect(loader.Paths()).To(HaveLen(4))
94+
95+
g.Expect(scanner.Scan(loader.RelPaths())).To(Succeed())
96+
97+
collection, err := attreg.MakePathCheckSummarySummaryCollection()
98+
g.Expect(err).NotTo(HaveOccurred())
99+
g.Expect(collection).ToNot(BeNil())
100+
g.Expect(collection.Providers).To(ConsistOf("git"))
101+
g.Expect(collection.EntryGroups).To(HaveLen(1))
102+
g.Expect(collection.EntryGroups[0]).To(HaveLen(5))
103+
80104
vcsSummary := attreg.BaseDirSummary()
81105
g.Expect(vcsSummary).ToNot(BeNil())
82106
summaryJSON, err := json.Marshal(vcsSummary.Full())
83107
g.Expect(err).NotTo(HaveOccurred())
84108
t.Logf("VCS info for %q: %s", tc.LoadPath, summaryJSON)
85109

110+
g.Expect(attreg.AssociateCoreStatements()).To(Succeed())
111+
86112
statements := attreg.GetStatements()
87-
g.Expect(statements).To(HaveLen(99))
113+
g.Expect(statements).To(HaveLen(1))
114+
g.Expect(statements[0].GetSubject()).To(HaveLen(4))
115+
116+
// TODO: validate schema
117+
118+
image, err := name.NewRepository("podinfo")
119+
g.Expect(err).NotTo(HaveOccurred())
120+
121+
semVerTags := oci.SemVerTagsFromAttestations(ctx, image.Tag("test.123456"), statements...)
122+
123+
g.Expect(semVerTags).To(HaveLen(len(tc.ExpectTags)))
88124
}
89125
}
90126

@@ -100,7 +136,7 @@ func (r *repos) init() error {
100136
return err
101137
}
102138
r.workDir = workDir
103-
tempDir, err := os.MkdirTemp(workDir, ".vcs-test-*")
139+
tempDir, err := os.MkdirTemp("", ".vcs-test-*")
104140
if err != nil {
105141
return err
106142
}
@@ -164,7 +200,6 @@ func (r *repos) clone(ctx context.Context, tc vcsTestCase) (string, error) {
164200
}
165201
opts := &gogit.CheckoutOptions{
166202
Hash: plumbing.NewHash(tc.CheckoutHash),
167-
//Branch: plumbing.ReferenceName(tc.Branch),
168203
}
169204

170205
if err := workTree.Checkout(opts); err != nil {

0 commit comments

Comments
 (0)