Skip to content

Commit

Permalink
IGNORE level results only show in debug mode (#148)
Browse files Browse the repository at this point in the history
* IGNORE level results only show in debug mode

* add test code
  • Loading branch information
tomoyamachi authored Sep 10, 2021
1 parent 3feabf0 commit d873a3d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
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

0 comments on commit d873a3d

Please sign in to comment.