-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metedata to the report file (#39)
* Add metedata to the report file This patch adds a new metadata section to the report file being generated by chain-bench. This initial version adds the generation date, and the check statistics which is useful to compare different scans and their evolutions over time. Fixes #38 * Split statistics struc Co-authored-by: Guy Ben-Aharon <[email protected]>
- Loading branch information
Showing
3 changed files
with
90 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package printer | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aquasecurity/chain-bench/internal/models/checkmodels" | ||
) | ||
|
||
type Statistics struct { | ||
Passed int | ||
Failed int | ||
Unknown int | ||
Total int | ||
} | ||
|
||
// NewStatistics initializes a new Statistics struct. | ||
func NewStatistics() Statistics { | ||
return Statistics{Passed: 0, Failed: 0, Unknown: 0, Total: 0} | ||
} | ||
|
||
// Add increments the value of a specific field as well as the total value. | ||
func (s *Statistics) Add(value checkmodels.ResultStatus) error { | ||
switch value { | ||
case checkmodels.Passed: | ||
s.Passed++ | ||
case checkmodels.Failed: | ||
s.Failed++ | ||
case checkmodels.Unknown: | ||
s.Unknown++ | ||
default: | ||
return fmt.Errorf("unknown statistical value: %s", value) | ||
} | ||
s.Total++ | ||
|
||
return nil | ||
} | ||
|
||
// Sub decrements the value of a specific field as well as the total value. | ||
func (s *Statistics) Sub(value checkmodels.ResultStatus) error { | ||
switch value { | ||
case checkmodels.Passed: | ||
s.Passed-- | ||
case checkmodels.Failed: | ||
s.Failed-- | ||
case checkmodels.Unknown: | ||
s.Unknown-- | ||
default: | ||
return fmt.Errorf("unknown statistical value: %s", value) | ||
} | ||
|
||
s.Total-- | ||
|
||
return nil | ||
} |