Skip to content

Commit e85f6c2

Browse files
WIP
1 parent 9b0dcfe commit e85f6c2

File tree

2 files changed

+56
-88
lines changed

2 files changed

+56
-88
lines changed

attest/vcs_test.go

Lines changed: 46 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -37,102 +37,56 @@ func (tc vcsTestCase) Name() string {
3737

3838
func TestVCS(t *testing.T) {
3939
testCases := []vcsTestCase{
40+
// {
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"},
47+
// },
48+
// {
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"},
56+
// },
4057
{
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"},
47-
},
48-
{
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"},
56-
},
57-
{
58-
URL: "https://github.com/stefanprodan/podinfo",
59-
CheckoutHash: "ba6f4ffd7cba98ea2ef52bee7c1bead8e1d6a7d3", // pre-6.7.0
60-
Branch: "master",
61-
LoadPath: "kustomize",
58+
URL: "https://github.com/errordeveloper/tape-git-testing",
59+
CheckoutHash: "3cad1d255c1d83b5e523de64d34758609498d81b",
60+
Branch: "main",
61+
LoadPath: "",
6262
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
6363
ExpectImageTags: nil,
6464
ExpectRawTags: nil,
6565
},
6666
{
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",
67+
URL: "https://github.com/errordeveloper/tape-git-testing",
68+
CheckoutTag: "0.0.1",
7969
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"},
70+
ExpectManifests: []string{"podinfo/kustomization.yaml", "podinfo/deployment.yaml", "podinfo/hpa.yaml", "podinfo/service.yaml"},
71+
ExpectImageTags: []string{"v0.0.1"},
72+
ExpectRawTags: []string{"0.0.1", "v0.0.1", "podinfo/v6.6.3"},
8373
},
8474
{
85-
URL: "https://github.com/fluxcd/pkg",
86-
CheckoutHash: "c647aea83012218c0353d3408b2237bb639578f3",
87-
Branch: "master",
88-
LoadPath: "version",
89-
ExpectImageTags: nil,
90-
ExpectRawTags: nil,
75+
URL: "https://github.com/errordeveloper/tape-git-testing",
76+
CheckoutTag: "v0.0.2",
77+
LoadPath: "podinfo",
78+
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
79+
ExpectImageTags: []string{"v0.0.2"},
80+
ExpectRawTags: []string{"0.0.2", "v0.0.2", "podinfo/v6.7.0"},
9181
},
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-
// },
12982
}
13083

13184
repos := &repos{}
13285
repos.init()
13386
defer repos.cleanup()
13487

135-
for _, tc := range testCases {
88+
for i := range testCases {
89+
tc := testCases[i]
13690
t.Run(tc.Name(), makeVCSTest(repos, tc))
13791
}
13892
}
@@ -158,7 +112,10 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
158112
scanner.WithProvinanceAttestor(attreg)
159113

160114
if tc.ExpectManifests != nil {
161-
g.Expect(loader.Paths()).To(ConsistOf(tc.ExpectManifests))
115+
g.Expect(loader.Paths()).To(HaveLen(len(tc.ExpectManifests)))
116+
for _, manifest := range tc.ExpectManifests {
117+
g.Expect(loader.ContainsRelPath(manifest)).To(BeTrue())
118+
}
162119
}
163120

164121
g.Expect(scanner.Scan(loader.RelPaths())).To(Succeed())
@@ -188,19 +145,22 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
188145
g.Expect(ok).To(BeTrue())
189146
ref := groupSummary.Git.Reference
190147
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))
148+
imageTagNames := make([]string, len(ref.Tags))
149+
for i, tag := range ref.Tags {
150+
imageTagNames[i] = tag.Name
193151
}
152+
g.Expect(imageTagNames).To(ConsistOf(tc.ExpectRawTags))
194153

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

198157
semVerTags := oci.SemVerTagsFromAttestations(ctx, image.Tag("test.123456"), statements...)
199-
200158
g.Expect(semVerTags).To(HaveLen(len(tc.ExpectImageTags)))
201-
for i, tag := range tc.ExpectImageTags {
202-
g.Expect(semVerTags[i].TagStr()).To(Equal(tag))
159+
semVerTagNames := make([]string, len(semVerTags))
160+
for i, tag := range semVerTags {
161+
semVerTagNames[i] = tag.TagStr()
203162
}
163+
g.Expect(semVerTagNames).To(ConsistOf(tc.ExpectImageTags))
204164
}
205165
}
206166

oci/artefact.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"maps"
1212
"os"
1313
"path/filepath"
14+
"strings"
1415
"time"
1516

1617
"golang.org/x/mod/semver"
@@ -399,10 +400,17 @@ func SemVerTagsFromAttestations(ctx context.Context, tag name.Tag, sourceAttesta
399400
}
400401
// TODO: detect tags with groupSummary.Path+"/" as prefix and priorities them
401402
tags := make([]name.Tag, 0, len(ref.Tags))
403+
set := make(map[string]struct{}, len(ref.Tags))
402404
for i := range ref.Tags {
403405
t := ref.Tags[i].Name
404-
if semver.IsValid(t) || semver.IsValid("v"+t) {
405-
tags = append(tags, tag.Context().Tag(ref.Tags[i].Name))
406+
if !strings.HasPrefix(t, "v") {
407+
t = "v" + t
408+
}
409+
if _, ok := set[t]; !ok {
410+
if semver.IsValid(t) {
411+
tags = append(tags, tag.Context().Tag(t))
412+
set[t] = struct{}{}
413+
}
406414
}
407415
}
408416
if len(tags) == 0 {

0 commit comments

Comments
 (0)