-
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.
- Loading branch information
Showing
3 changed files
with
58 additions
and
34 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 | ||
} |