@@ -15,18 +15,16 @@ import (
15
15
. "github.com/onsi/gomega"
16
16
17
17
. "github.com/errordeveloper/tape/attest"
18
+ "github.com/errordeveloper/tape/attest/vcs/git"
18
19
"github.com/errordeveloper/tape/manifest/imagescanner"
19
20
"github.com/errordeveloper/tape/manifest/loader"
20
21
"github.com/errordeveloper/tape/oci"
21
22
)
22
23
23
24
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
30
28
}
31
29
32
30
func (tc vcsTestCase ) Name () string {
@@ -40,25 +38,94 @@ func (tc vcsTestCase) Name() string {
40
38
func TestVCS (t * testing.T ) {
41
39
testCases := []vcsTestCase {
42
40
{
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" },
47
47
},
48
48
{
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" },
54
56
},
55
57
{
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 ,
61
65
},
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
+ // },
62
129
}
63
130
64
131
repos := & repos {}
@@ -90,7 +157,9 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
90
157
scanner := imagescanner .NewDefaultImageScanner ()
91
158
scanner .WithProvinanceAttestor (attreg )
92
159
93
- g .Expect (loader .Paths ()).To (HaveLen (4 ))
160
+ if tc .ExpectManifests != nil {
161
+ g .Expect (loader .Paths ()).To (ConsistOf (tc .ExpectManifests ))
162
+ }
94
163
95
164
g .Expect (scanner .Scan (loader .RelPaths ())).To (Succeed ())
96
165
@@ -115,12 +184,23 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
115
184
116
185
// TODO: validate schema
117
186
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
+
118
195
image , err := name .NewRepository ("podinfo" )
119
196
g .Expect (err ).NotTo (HaveOccurred ())
120
197
121
198
semVerTags := oci .SemVerTagsFromAttestations (ctx , image .Tag ("test.123456" ), statements ... )
122
199
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
+ }
124
204
}
125
205
}
126
206
0 commit comments