@@ -16,6 +16,7 @@ import {
16
16
Sarif ,
17
17
getSarifOutputType ,
18
18
QueryMetadata ,
19
+ getBqrsResultCount ,
19
20
} from "./codeql" ;
20
21
21
22
const test = anyTest as TestFn < { db : string ; tmpDir : string } > ;
@@ -260,3 +261,49 @@ test("getting the SARIF output type when the `@kind` metadata is compatible with
260
261
261
262
t . is ( getSarifOutputType ( queryMetadata , compatibleQueryKinds ) , "problem" ) ;
262
263
} ) ;
264
+
265
+ test ( "uses result count from #select result set if it exists" , ( t ) => {
266
+ const bqrsInfo : BQRSInfo = {
267
+ resultSets : [ { name : "#select" , rows : 3 } ] ,
268
+ compatibleQueryKinds : [ ] ,
269
+ } ;
270
+
271
+ t . is ( getBqrsResultCount ( bqrsInfo ) , 3 ) ;
272
+ } ) ;
273
+
274
+ test ( "uses result count from problems result set if it exists" , ( t ) => {
275
+ const bqrsInfo : BQRSInfo = {
276
+ resultSets : [ { name : "problems" , rows : 4 } ] ,
277
+ compatibleQueryKinds : [ ] ,
278
+ } ;
279
+
280
+ t . is ( getBqrsResultCount ( bqrsInfo ) , 4 ) ;
281
+ } ) ;
282
+
283
+ test ( "uses result count from #select result set if both #select and problems result sets exist" , ( t ) => {
284
+ const bqrsInfo : BQRSInfo = {
285
+ resultSets : [
286
+ { name : "#select" , rows : 3 } ,
287
+ { name : "problems" , rows : 4 } ,
288
+ ] ,
289
+ compatibleQueryKinds : [ ] ,
290
+ } ;
291
+
292
+ t . is ( getBqrsResultCount ( bqrsInfo ) , 3 ) ;
293
+ } ) ;
294
+
295
+ test ( "throws error if neither #select or problems result sets exist" , ( t ) => {
296
+ const bqrsInfo : BQRSInfo = {
297
+ resultSets : [
298
+ { name : "something" , rows : 13 } ,
299
+ { name : "unknown" , rows : 42 } ,
300
+ ] ,
301
+ compatibleQueryKinds : [ ] ,
302
+ } ;
303
+
304
+ const error = t . throws ( ( ) => getBqrsResultCount ( bqrsInfo ) ) ;
305
+ t . deepEqual (
306
+ error ?. message ,
307
+ "BQRS does not contain any result sets matching known names. Expected one of #select or problems but found something, unknown" ,
308
+ ) ;
309
+ } ) ;
0 commit comments