Skip to content

Commit

Permalink
Addressed issue #417
Browse files Browse the repository at this point in the history
Some things were being missed due to parsing issues, which have now been corrected.

Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Jan 19, 2024
1 parent 58fab1e commit 6fd23f0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
29 changes: 29 additions & 0 deletions functions/core/length_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,32 @@ tags:
assert.Len(t, res, 0) // should just do nothing.

}

func TestLength_RunRule_TestPathAllTags(t *testing.T) {

sampleYaml := `
tags:
- name: "taggy"
description: 10.12
- name: "tiggy"
description: 1.22`

path := "$.tags[*]"

nodes, _ := utils.FindNodes([]byte(sampleYaml), path)

ops := make(map[string]string)
ops["max"] = "1"
ops["min"] = "0"

rule := buildCoreTestRule(path, model.SeverityError, "length", "name", ops)
ctx := buildCoreTestContext(model.CastToRuleAction(rule.Then), ops)
ctx.Given = path
ctx.Rule = &rule

le := Length{}
res := le.RunRule(nodes, ctx)

assert.Len(t, res, 2)

}
18 changes: 14 additions & 4 deletions model/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func NewRuleResultSet(results []RuleFunctionResult) *RuleResultSet {
Results: pointerResults,
categoryMap: make(map[*RuleCategory][]*RuleFunctionResult),
}
defer rrs.GetErrorCount()
defer rrs.GetInfoCount()
defer rrs.GetWarnCount()
rrs.GetErrorCount()
rrs.GetInfoCount()
rrs.GetWarnCount()
return rrs
}

Expand Down Expand Up @@ -95,6 +95,8 @@ func (rr *RuleResultSet) GenerateSpectralReport(source string) []reports.Spectra
sev = 2
case SeverityHint:
sev = 3
default:
sev = 3
}

resultRange := reports.Range{
Expand Down Expand Up @@ -220,6 +222,10 @@ func (rr *RuleResultSet) GetWarningsByRuleCategory(category string) []*RuleFunct
case SeverityWarn:
filtered = append(filtered, cat)
}
// by default rules with no severity, are warnings.
if cat.Rule.Severity == "" {
filtered = append(filtered, cat)
}
}
return filtered
}
Expand Down Expand Up @@ -300,10 +306,14 @@ func (rr *RuleResultSet) GetResultsForCategoryWithLimit(category string, limit i
func getCount(rr *RuleResultSet, severity string) int {
c := 0
for _, res := range rr.Results {
if res.Rule != nil && res.Rule.Severity != "" {
if res.Rule != nil {
if res.Rule.Severity == severity {
c++
}
// if there is no severity, mark it as a warning by default.
if res.Rule.Severity == "" && severity == SeverityWarn {
c++
}
}
}
return c
Expand Down
3 changes: 3 additions & 0 deletions model/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func countPropsInterface(options map[string]interface{}, numProps int) int {
if _, ok := v.(int); ok {
numProps++
}
if _, ok := v.(float64); ok {
numProps++
}
if _, ok := v.(bool); ok {
numProps++
}
Expand Down

0 comments on commit 6fd23f0

Please sign in to comment.