Skip to content

Adding default values for `flags` array to avoid failure

Zach Rice requested to merge flags-compare-report into master

What does this MR do?

Adds a default flags array so that jq does not fail during the comparison. Similar to the fix presented in !215 (merged), this diff does not actually provide a filled in flags array but will at least get the developer looking at the incorrect lines in the report.

Files to compare:

  1. gl-sast-report-with-fp-flags.json
  2. gl-sast-report-got.json

Before change:

Error: jq encountered an error while attempting to parse the file: 'gl-sast-report-got.json': 'jq: error (at gl-sast-report-got.json:141): null (null) cannot be sorted, as it is not an array'. It appears as though the JSON file 'gl-sast-report-got.json' consists of some objects which contain array elements, while other objects are missing these elements. In order for jq to be able to sort the file, all objects (entries) in the file must have the _same_ structure. Please ensure that you've set the correct report-type value for the given report. If the report-type has been set correctly, then you'll need to update the `jq_filter` variable of this script to insert blank `[]` entries for these missing array elements using the `map_values` function.

After change:

Error occurred while comparing actual report 'gl-sast-report-got.json' against expected report 'gl-sast-report-with-fp-flags.json': report contents differ:

--- gl-sast-report-with-fp-flags-sanitized.json 2021-08-11 11:59:40.000000000 -0500
+++ gl-sast-report-got-sanitized.json   2021-08-11 11:59:40.000000000 -0500
@@ -42,7 +42,6 @@
         "id": "brakeman",
         "name": "Brakeman"
       },
-      "flags": [],
       "location": {
         "file": "app/controllers/groups_controller.rb",
         "start_line": 6,
@@ -60,7 +59,8 @@
       "links": [],
       "tracking": {
         "items": []
-      }
+      },
+      "flags": []
     },
     {
       "category": "sast",

What are the relevant issue numbers?

Does this MR meet the acceptance criteria?

Edited by Zach Rice

Merge request reports