Skip to content

Commit 9b0dcfe

Browse files
WIP
1 parent 4706e15 commit 9b0dcfe

File tree

1 file changed

+102
-22
lines changed

1 file changed

+102
-22
lines changed

attest/vcs_test.go

Lines changed: 102 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,16 @@ import (
1515
. "github.com/onsi/gomega"
1616

1717
. "github.com/errordeveloper/tape/attest"
18+
"github.com/errordeveloper/tape/attest/vcs/git"
1819
"github.com/errordeveloper/tape/manifest/imagescanner"
1920
"github.com/errordeveloper/tape/manifest/loader"
2021
"github.com/errordeveloper/tape/oci"
2122
)
2223

2324
type vcsTestCase struct {
24-
URL string
25-
CheckoutTag string
26-
CheckoutHash string
27-
Branch string
28-
LoadPath string
29-
ExpectTags []string
25+
URL, CheckoutTag, CheckoutHash, Branch string
26+
LoadPath string
27+
ExpectManifests, ExpectImageTags, ExpectRawTags []string
3028
}
3129

3230
func (tc vcsTestCase) Name() string {
@@ -40,25 +38,94 @@ func (tc vcsTestCase) Name() string {
4038
func TestVCS(t *testing.T) {
4139
testCases := []vcsTestCase{
4240
{
43-
URL: "https://github.com/stefanprodan/podinfo",
44-
CheckoutTag: "6.7.0", // => 0b1481aa8ed0a6c34af84f779824a74200d5c1d6
45-
LoadPath: "kustomize",
46-
ExpectTags: []string{"6.7.0"},
41+
URL: "https://github.com/stefanprodan/podinfo",
42+
CheckoutTag: "6.7.0", // => 0b1481aa8ed0a6c34af84f779824a74200d5c1d6
43+
LoadPath: "kustomize",
44+
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
45+
ExpectImageTags: []string{"6.7.0"},
46+
ExpectRawTags: []string{"6.7.0"},
4747
},
4848
{
49-
URL: "https://github.com/stefanprodan/podinfo",
50-
CheckoutHash: "0b1481aa8ed0a6c34af84f779824a74200d5c1d6", // => 6.7.0
51-
Branch: "master",
52-
LoadPath: "kustomize",
53-
ExpectTags: []string{"6.7.0"},
49+
URL: "https://github.com/stefanprodan/podinfo",
50+
CheckoutHash: "0b1481aa8ed0a6c34af84f779824a74200d5c1d6", // => 6.7.0
51+
Branch: "master",
52+
LoadPath: "kustomize",
53+
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
54+
ExpectImageTags: []string{"6.7.0"},
55+
ExpectRawTags: []string{"6.7.0"},
5456
},
5557
{
56-
URL: "https://github.com/stefanprodan/podinfo",
57-
CheckoutHash: "ba6f4ffd7cba98ea2ef52bee7c1bead8e1d6a7d3", // pre-6.7.0
58-
Branch: "master",
59-
LoadPath: "kustomize",
60-
ExpectTags: nil,
58+
URL: "https://github.com/stefanprodan/podinfo",
59+
CheckoutHash: "ba6f4ffd7cba98ea2ef52bee7c1bead8e1d6a7d3", // pre-6.7.0
60+
Branch: "master",
61+
LoadPath: "kustomize",
62+
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
63+
ExpectImageTags: nil,
64+
ExpectRawTags: nil,
6165
},
66+
{
67+
URL: "https://github.com/stefanprodan/podinfo",
68+
CheckoutTag: "6.6.1",
69+
Branch: "master",
70+
LoadPath: "kustomize",
71+
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
72+
ExpectImageTags: []string{"6.6.1"},
73+
ExpectRawTags: []string{"6.6.1"},
74+
},
75+
{
76+
URL: "https://github.com/stefanprodan/podinfo",
77+
CheckoutTag: "6.6.2",
78+
Branch: "master",
79+
LoadPath: "",
80+
ExpectManifests: []string{"kustomize/kustomization.yaml", "kustomize/deployment.yaml", "kustomize/hpa.yaml", "kustomize/service.yaml"},
81+
ExpectImageTags: []string{"6.6.1"},
82+
ExpectRawTags: []string{"6.6.1"},
83+
},
84+
{
85+
URL: "https://github.com/fluxcd/pkg",
86+
CheckoutHash: "c647aea83012218c0353d3408b2237bb639578f3",
87+
Branch: "master",
88+
LoadPath: "version",
89+
ExpectImageTags: nil,
90+
ExpectRawTags: nil,
91+
},
92+
// {
93+
// URL: "https://github.com/fluxcd/pkg",
94+
// CheckoutTag: "version/v0.4.0",
95+
// Branch: "master",
96+
// LoadPath: "version",
97+
// ExpectImageTags: nil, // TODO: should be 0.4.0
98+
// ExpectRawTags: []string{
99+
// "version/v0.4.0",
100+
// "testserver/v0.7.0",
101+
// "tar/v0.7.0",
102+
// "ssh/v0.13.0",
103+
// "ssa/v0.39.1",
104+
// "ssa/v0.39.0",
105+
// "sourceignore/v0.7.0",
106+
// "runtime/v0.47.1",
107+
// "runtime/v0.47.0",
108+
// "oci/v0.38.1",
109+
// "oci/v0.38.0",
110+
// "oci/v0.37.1",
111+
// "oci/v0.37.0",
112+
// "masktoken/v0.4.0",
113+
// "lockedfile/v0.3.0",
114+
// "kustomize/v1.11.0",
115+
// "http/transport/v0.3.0",
116+
// "http/fetch/v0.11.0",
117+
// "helmtestserver/v0.18.0",
118+
// "gittestserver/v0.12.0",
119+
// "git/v0.19.0",
120+
// "git/gogit/v0.19.0",
121+
// "envsubst/v1.1.0",
122+
// "cache/v0.0.1",
123+
// "apis/meta/v1.5.0",
124+
// "apis/kustomize/v1.5.0",
125+
// "apis/event/v0.9.0",
126+
// "apis/acl/v0.3.0",
127+
// },
128+
// },
62129
}
63130

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

93-
g.Expect(loader.Paths()).To(HaveLen(4))
160+
if tc.ExpectManifests != nil {
161+
g.Expect(loader.Paths()).To(ConsistOf(tc.ExpectManifests))
162+
}
94163

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

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

116185
// TODO: validate schema
117186

187+
groupSummary, ok := vcsSummary.Full().(*git.Summary)
188+
g.Expect(ok).To(BeTrue())
189+
ref := groupSummary.Git.Reference
190+
g.Expect(ref.Tags).To(HaveLen(len(tc.ExpectRawTags)))
191+
for i, tag := range tc.ExpectRawTags {
192+
g.Expect(ref.Tags[i].Name).To(Equal(tag))
193+
}
194+
118195
image, err := name.NewRepository("podinfo")
119196
g.Expect(err).NotTo(HaveOccurred())
120197

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

123-
g.Expect(semVerTags).To(HaveLen(len(tc.ExpectTags)))
200+
g.Expect(semVerTags).To(HaveLen(len(tc.ExpectImageTags)))
201+
for i, tag := range tc.ExpectImageTags {
202+
g.Expect(semVerTags[i].TagStr()).To(Equal(tag))
203+
}
124204
}
125205
}
126206

0 commit comments

Comments
 (0)