@@ -245,74 +245,117 @@ func TestNewReport(t *testing.T) {
245245 ID : "b_rule" ,
246246 Name : "My Rule B" ,
247247 },
248- {
249- ID : "c_rule" ,
250- Name : "My Rule C (missing)" ,
251- },
252248 },
253249 },
254250 },
255251 }
256252
257- resultCollection := & results.ResultCollection {
258- & results.Result {ID : rules .RuleToResult ("a_rule" ), Violations : []string {}},
259- & results.Result {ID : rules .RuleToResult ("b_rule" ), Violations : []string {"violation" }},
260- }
253+ t .Run ("returns a report" , func (t * testing.T ) {
254+ resultCollection := & results.ResultCollection {
255+ & results.Result {ID : rules .RuleToResult ("a_rule" ), Violations : []string {}},
256+ & results.Result {ID : rules .RuleToResult ("b_rule" ), Violations : []string {"violation" }},
257+ }
261258
262- got , err := NewReport (examplePackage , resultCollection )
263- if err != nil {
264- t .Fatalf ("NewReport returned error: %v" , err )
265- }
259+ got , err := NewReport (examplePackage , resultCollection )
260+ if err != nil {
261+ t .Fatalf ("NewReport returned error: %v" , err )
262+ }
266263
267- want := api.Report {
268- PreflightVersion : version .PreflightVersion ,
269- Package : examplePackage .ID ,
270- PackageInformation : api.PackageInformation {
271- Namespace : examplePackage .Namespace ,
272- ID : examplePackage .ID ,
273- Version : examplePackage .PackageVersion ,
274- SchemaVersion : examplePackage .SchemaVersion ,
275- },
276- Name : examplePackage .Name ,
277- Description : examplePackage .Description ,
278- Sections : []api.ReportSection {
279- api.ReportSection {
280- ID : "a_section" ,
281- Name : "My section" ,
282- Rules : []api.ReportRule {
283- api.ReportRule {
284- ID : "a_rule" ,
285- Name : "My Rule A" ,
286- Manual : false ,
287- Success : true ,
288- Missing : false ,
289- Links : []string {},
290- Violations : []string {},
291- },
292- api.ReportRule {
293- ID : "b_rule" ,
294- Name : "My Rule B" ,
295- Manual : false ,
296- Success : false ,
297- Missing : false ,
298- Links : []string {},
299- Violations : []string {"violation" },
264+ want := api.Report {
265+ PreflightVersion : version .PreflightVersion ,
266+ Package : examplePackage .ID ,
267+ PackageInformation : api.PackageInformation {
268+ Namespace : examplePackage .Namespace ,
269+ ID : examplePackage .ID ,
270+ Version : examplePackage .PackageVersion ,
271+ SchemaVersion : examplePackage .SchemaVersion ,
272+ },
273+ Name : examplePackage .Name ,
274+ Description : examplePackage .Description ,
275+ Sections : []api.ReportSection {
276+ api.ReportSection {
277+ ID : "a_section" ,
278+ Name : "My section" ,
279+ Rules : []api.ReportRule {
280+ api.ReportRule {
281+ ID : "a_rule" ,
282+ Name : "My Rule A" ,
283+ Manual : false ,
284+ Success : true ,
285+ Missing : false ,
286+ Links : []string {},
287+ Violations : []string {},
288+ },
289+ api.ReportRule {
290+ ID : "b_rule" ,
291+ Name : "My Rule B" ,
292+ Manual : false ,
293+ Success : false ,
294+ Missing : false ,
295+ Links : []string {},
296+ Violations : []string {"violation" },
297+ },
300298 },
301- api.ReportRule {
302- ID : "c_rule" ,
303- Name : "My Rule C (missing)" ,
304- Manual : false ,
305- Success : false ,
306- Missing : true ,
307- Links : []string {},
308- Violations : []string {},
299+ },
300+ },
301+ }
302+
303+ if ! reflect .DeepEqual (got , want ) {
304+ t .Fatalf ("got != want; got=%+v, want=%+v" , got , want )
305+ }
306+ })
307+
308+ t .Run ("returns error MissingRegoDefinitionError if definition missing" , func (t * testing.T ) {
309+ resultCollection := & results.ResultCollection {
310+ & results.Result {ID : rules .RuleToResult ("a_rule" ), Violations : []string {}},
311+ }
312+
313+ got , err := NewReport (examplePackage , resultCollection )
314+ if _ , ok := err .(* MissingRegoDefinitionError ); ! ok {
315+ t .Errorf ("expected MissingRegoDefinitionError but got: %v" , err )
316+ }
317+
318+ want := api.Report {
319+ PreflightVersion : version .PreflightVersion ,
320+ Package : examplePackage .ID ,
321+ PackageInformation : api.PackageInformation {
322+ Namespace : examplePackage .Namespace ,
323+ ID : examplePackage .ID ,
324+ Version : examplePackage .PackageVersion ,
325+ SchemaVersion : examplePackage .SchemaVersion ,
326+ },
327+ Name : examplePackage .Name ,
328+ Description : examplePackage .Description ,
329+ Sections : []api.ReportSection {
330+ api.ReportSection {
331+ ID : "a_section" ,
332+ Name : "My section" ,
333+ Rules : []api.ReportRule {
334+ api.ReportRule {
335+ ID : "a_rule" ,
336+ Name : "My Rule A" ,
337+ Manual : false ,
338+ Success : true ,
339+ Missing : false ,
340+ Links : []string {},
341+ Violations : []string {},
342+ },
343+ api.ReportRule {
344+ ID : "b_rule" ,
345+ Name : "My Rule B" ,
346+ Manual : false ,
347+ Success : false ,
348+ Missing : true ,
349+ Links : []string {},
350+ Violations : []string {},
351+ },
309352 },
310353 },
311354 },
312- },
313- }
355+ }
314356
315- if ! reflect .DeepEqual (got , want ) {
316- t .Fatalf ("got != want; got=%+v, want=%+v" , got , want )
317- }
357+ if ! reflect .DeepEqual (got , want ) {
358+ t .Fatalf ("got != want; got=%+v, want=%+v" , got , want )
359+ }
360+ })
318361}
0 commit comments