Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNORE level results only show in debug mode #148

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func Run(c *cli.Context) (err error) {

log.Logger.Debug("End assessments...")

assessmentMap := types.CreateAssessmentMap(assessments, config.Conf.IgnoreMap)
assessmentMap := types.CreateAssessmentMap(assessments, config.Conf.IgnoreMap, debug)
// Store ignore checkpoint code
o := c.String("output")
output := os.Stdout
Expand Down
6 changes: 5 additions & 1 deletion pkg/types/assessment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ type CodeInfo struct {
}
type AssessmentMap map[string]CodeInfo

func CreateAssessmentMap(as AssessmentSlice, ignoreMap map[string]struct{}) AssessmentMap {
func CreateAssessmentMap(as AssessmentSlice, ignoreMap map[string]struct{}, debug bool) AssessmentMap {
asMap := AssessmentMap{}
for _, a := range as {
level := a.Level
if level == 0 {
level = DefaultLevelMap[a.Code]
}
if _, ok := ignoreMap[a.Code]; ok {
// ignore level only shows DEBUG mode
if !debug {
continue
}
level = IgnoreLevel
}
if _, ok := asMap[a.Code]; !ok {
Expand Down
24 changes: 23 additions & 1 deletion pkg/types/assessment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func TestCreateAssessmentMap(t *testing.T) {
testcases := map[string]struct {
as AssessmentSlice
ig map[string]struct{}
debug bool
expected AssessmentMap
}{
"OK": {
Expand Down Expand Up @@ -48,6 +49,27 @@ func TestCreateAssessmentMap(t *testing.T) {
{Code: "a", Filename: "b"},
},
ig: map[string]struct{}{"b": {}},
expected: map[string]CodeInfo{
"a": {
Code: "a",
Level: 0,
Assessments: []*Assessment{
{Code: "a", Filename: "a"},
{Code: "a", Filename: "c"},
{Code: "a", Filename: "b"},
},
},
},
},
"IgnoreBwithDebug": {
as: AssessmentSlice{
{Code: "a", Filename: "a"},
{Code: "b", Filename: "b"},
{Code: "a", Filename: "c"},
{Code: "a", Filename: "b"},
},
ig: map[string]struct{}{"b": {}},
debug: true,
expected: map[string]CodeInfo{
"a": {
Code: "a",
Expand All @@ -70,7 +92,7 @@ func TestCreateAssessmentMap(t *testing.T) {
}

for name, v := range testcases {
actual := CreateAssessmentMap(v.as, v.ig)
actual := CreateAssessmentMap(v.as, v.ig, v.debug)
cmpopts := []cmp.Option{
cmpopts.SortSlices(func(x, y Assessment) bool {
if x.Code == y.Code {
Expand Down