@@ -10,12 +10,14 @@ import (
10
10
11
11
gogit "github.com/go-git/go-git/v5"
12
12
"github.com/go-git/go-git/v5/plumbing"
13
+ "github.com/google/go-containerregistry/pkg/name"
13
14
14
15
. "github.com/onsi/gomega"
15
16
16
17
. "github.com/errordeveloper/tape/attest"
17
18
"github.com/errordeveloper/tape/manifest/imagescanner"
18
19
"github.com/errordeveloper/tape/manifest/loader"
20
+ "github.com/errordeveloper/tape/oci"
19
21
)
20
22
21
23
type vcsTestCase struct {
@@ -24,6 +26,7 @@ type vcsTestCase struct {
24
26
CheckoutHash string
25
27
Branch string
26
28
LoadPath string
29
+ ExpectTags []string
27
30
}
28
31
29
32
func (tc vcsTestCase ) Name () string {
@@ -40,12 +43,21 @@ func TestVCS(t *testing.T) {
40
43
URL : "https://github.com/stefanprodan/podinfo" ,
41
44
CheckoutTag : "6.7.0" , // => 0b1481aa8ed0a6c34af84f779824a74200d5c1d6
42
45
LoadPath : "kustomize" ,
46
+ ExpectTags : []string {"6.7.0" },
43
47
},
44
48
{
45
49
URL : "https://github.com/stefanprodan/podinfo" ,
46
50
CheckoutHash : "0b1481aa8ed0a6c34af84f779824a74200d5c1d6" , // => 6.7.0
47
51
Branch : "master" ,
48
52
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 ,
49
61
},
50
62
}
51
63
@@ -62,7 +74,8 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
62
74
return func (t * testing.T ) {
63
75
g := NewWithT (t )
64
76
65
- checkoutPath , err := repos .clone (context .Background (), tc )
77
+ ctx := context .Background ()
78
+ checkoutPath , err := repos .clone (ctx , tc )
66
79
g .Expect (err ).NotTo (HaveOccurred ())
67
80
68
81
loadPath := filepath .Join (checkoutPath , tc .LoadPath )
@@ -77,14 +90,37 @@ func makeVCSTest(repos *repos, tc vcsTestCase) func(t *testing.T) {
77
90
scanner := imagescanner .NewDefaultImageScanner ()
78
91
scanner .WithProvinanceAttestor (attreg )
79
92
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
+
80
104
vcsSummary := attreg .BaseDirSummary ()
81
105
g .Expect (vcsSummary ).ToNot (BeNil ())
82
106
summaryJSON , err := json .Marshal (vcsSummary .Full ())
83
107
g .Expect (err ).NotTo (HaveOccurred ())
84
108
t .Logf ("VCS info for %q: %s" , tc .LoadPath , summaryJSON )
85
109
110
+ g .Expect (attreg .AssociateCoreStatements ()).To (Succeed ())
111
+
86
112
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 )))
88
124
}
89
125
}
90
126
@@ -100,7 +136,7 @@ func (r *repos) init() error {
100
136
return err
101
137
}
102
138
r .workDir = workDir
103
- tempDir , err := os .MkdirTemp (workDir , ".vcs-test-*" )
139
+ tempDir , err := os .MkdirTemp ("" , ".vcs-test-*" )
104
140
if err != nil {
105
141
return err
106
142
}
@@ -164,7 +200,6 @@ func (r *repos) clone(ctx context.Context, tc vcsTestCase) (string, error) {
164
200
}
165
201
opts := & gogit.CheckoutOptions {
166
202
Hash : plumbing .NewHash (tc .CheckoutHash ),
167
- //Branch: plumbing.ReferenceName(tc.Branch),
168
203
}
169
204
170
205
if err := workTree .Checkout (opts ); err != nil {
0 commit comments