@@ -76,6 +76,10 @@ func Test_SAST(t *testing.T) {
76
76
},
77
77
},
78
78
searchresult : clients.SearchResponse {},
79
+ searchRequest : clients.SearchRequest {
80
+ Query : "github/codeql-action/analyze" ,
81
+ Path : "/.github/workflows" ,
82
+ },
79
83
checkRuns : []clients.CheckRun {
80
84
{
81
85
Status : "completed" ,
@@ -101,6 +105,10 @@ func Test_SAST(t *testing.T) {
101
105
},
102
106
},
103
107
searchresult : clients.SearchResponse {},
108
+ searchRequest : clients.SearchRequest {
109
+ Query : "github/codeql-action/analyze" ,
110
+ Path : "/.github/workflows" ,
111
+ },
104
112
checkRuns : []clients.CheckRun {
105
113
{
106
114
Status : "completed" ,
@@ -126,6 +134,10 @@ func Test_SAST(t *testing.T) {
126
134
},
127
135
},
128
136
searchresult : clients.SearchResponse {},
137
+ searchRequest : clients.SearchRequest {
138
+ Query : "github/codeql-action/analyze" ,
139
+ Path : "/.github/workflows" ,
140
+ },
129
141
checkRuns : []clients.CheckRun {
130
142
{
131
143
Status : "completed" ,
@@ -152,6 +164,10 @@ func Test_SAST(t *testing.T) {
152
164
},
153
165
},
154
166
searchresult : clients.SearchResponse {},
167
+ searchRequest : clients.SearchRequest {
168
+ Query : "github/codeql-action/analyze" ,
169
+ Path : "/.github/workflows" ,
170
+ },
155
171
checkRuns : []clients.CheckRun {
156
172
{
157
173
Status : "completed" ,
@@ -178,7 +194,11 @@ func Test_SAST(t *testing.T) {
178
194
},
179
195
},
180
196
searchresult : clients.SearchResponse {},
181
- path : ".github/workflows/airflow-codeql-workflow.yaml" ,
197
+ searchRequest : clients.SearchRequest {
198
+ Query : "github/codeql-action/analyze" ,
199
+ Path : "/.github/workflows" ,
200
+ },
201
+ path : ".github/workflows/airflow-codeql-workflow.yaml" ,
182
202
expected : scut.TestReturn {
183
203
Score : 7 ,
184
204
NumberOfWarn : 1 ,
@@ -196,6 +216,10 @@ func Test_SAST(t *testing.T) {
196
216
},
197
217
},
198
218
searchresult : clients.SearchResponse {},
219
+ searchRequest : clients.SearchRequest {
220
+ Query : "github/codeql-action/analyze" ,
221
+ Path : "/.github/workflows" ,
222
+ },
199
223
checkRuns : []clients.CheckRun {
200
224
{
201
225
Status : "completed" ,
@@ -231,6 +255,10 @@ func Test_SAST(t *testing.T) {
231
255
},
232
256
},
233
257
searchresult : clients.SearchResponse {},
258
+ searchRequest : clients.SearchRequest {
259
+ Query : "github/codeql-action/analyze" ,
260
+ Path : "/.github/workflows" ,
261
+ },
234
262
checkRuns : []clients.CheckRun {
235
263
{
236
264
Status : "completed" ,
@@ -271,6 +299,10 @@ func Test_SAST(t *testing.T) {
271
299
},
272
300
},
273
301
searchresult : clients.SearchResponse {},
302
+ searchRequest : clients.SearchRequest {
303
+ Query : "github/codeql-action/analyze" ,
304
+ Path : "/.github/workflows" ,
305
+ },
274
306
checkRuns : []clients.CheckRun {
275
307
{
276
308
Status : "notCompletedForTestingOnly" ,
@@ -294,12 +326,51 @@ func Test_SAST(t *testing.T) {
294
326
NumberOfInfo : 1 ,
295
327
},
296
328
},
329
+ {
330
+ name : `Trivy workflow with commits` ,
331
+ err : nil ,
332
+ commits : []clients.Commit {
333
+ {
334
+ AssociatedMergeRequest : clients.PullRequest {
335
+ MergedAt : time .Now ().Add (time .Hour - 1 ),
336
+ },
337
+ },
338
+ {
339
+ AssociatedMergeRequest : clients.PullRequest {
340
+ MergedAt : time .Now ().Add (time .Hour - 2 ),
341
+ },
342
+ },
343
+ },
344
+ searchresult : clients.SearchResponse {},
345
+ searchRequest : clients.SearchRequest {
346
+ Query : "github/aquasecurity/trivy-action" ,
347
+ Path : "/.github/workflows" ,
348
+ },
349
+ checkRuns : []clients.CheckRun {
350
+ {
351
+ Status : "completed" ,
352
+ Conclusion : "success" ,
353
+ App : clients.CheckRunApp {
354
+ Slug : "aqua-security-trivy" ,
355
+ },
356
+ },
357
+ {
358
+ Status : "completed" ,
359
+ Conclusion : "success" ,
360
+ App : clients.CheckRunApp {
361
+ Slug : "aqua-security-trivy" ,
362
+ },
363
+ },
364
+ },
365
+ path : ".github/workflows/github-trivy-workflow.yaml" ,
366
+ expected : scut.TestReturn {
367
+ Score : checker .MaxResultScore ,
368
+ NumberOfDebug : 2 ,
369
+ NumberOfInfo : 2 ,
370
+ },
371
+ },
297
372
}
298
373
for _ , tt := range tests {
299
- searchRequest := clients.SearchRequest {
300
- Query : "github/codeql-action/analyze" ,
301
- Path : "/.github/workflows" ,
302
- }
303
374
t .Run (tt .name , func (t * testing.T ) {
304
375
t .Parallel ()
305
376
ctrl := gomock .NewController (t )
@@ -311,7 +382,7 @@ func Test_SAST(t *testing.T) {
311
382
return tt .commits , tt .err
312
383
})
313
384
mockRepoClient .EXPECT ().ListCheckRunsForRef ("" ).Return (tt .checkRuns , nil ).AnyTimes ()
314
- mockRepoClient .EXPECT ().Search (searchRequest ).Return (tt .searchresult , nil ).AnyTimes ()
385
+ mockRepoClient .EXPECT ().Search (tt . searchRequest ).Return (tt .searchresult , nil ).AnyTimes ()
315
386
mockRepoClient .EXPECT ().ListFiles (gomock .Any ()).DoAndReturn (
316
387
func (predicate func (string ) (bool , error )) ([]string , error ) {
317
388
if strings .Contains (tt .path , "pom" ) {
0 commit comments