1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-14 11:57:32 +00:00

Update coverage config

Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
This commit is contained in:
Frank Jogeleit 2024-04-24 13:55:59 +02:00
parent feb0548fe4
commit 39fc42a28e
4 changed files with 47 additions and 46 deletions

View file

@ -21,7 +21,9 @@ test:
.PHONY: coverage
coverage:
go test -v ./... -covermode=count -coverprofile=coverage.out -timeout=30s
go test -v ./... -covermode=count -coverprofile=coverage.out.tmp -timeout=30s
cat coverage.out.tmp | grep -v "github.com/kyverno/policy-reporter/cmd/" | grep -v "github.com/kyverno/policy-reporter/main.go" | grep -v "github.com/kyverno/policy-reporter/pkg/crd/" > coverage.out
rm coverage.out.tmp
.PHONY: build
build: prepare

View file

@ -65,4 +65,26 @@ func TestClusterPolicyReport(t *testing.T) {
t.Errorf("expected critical severity, got: %s", cpolr.GetSeverities()[1])
}
})
t.Run("Results", func(t *testing.T) {
polr := &v1alpha2.ClusterPolicyReport{}
if s := len(polr.GetResults()); s != 0 {
t.Errorf("expected empty results, got: %d", s)
}
polr.SetResults([]v1alpha2.PolicyReportResult{
{Policy: "require-label", Result: v1alpha2.StatusPass},
})
if s := len(polr.GetResults()); s != 1 {
t.Errorf("expected 1 result, got: %d", s)
}
})
t.Run("Summary", func(t *testing.T) {
polr := &v1alpha2.ClusterPolicyReport{Summary: v1alpha2.PolicyReportSummary{Pass: 1}}
if s := polr.GetSummary().Pass; s != 1 {
t.Errorf("expected 1 pass result, got: %d", s)
}
})
}

View file

@ -65,4 +65,26 @@ func TestPolicyReport(t *testing.T) {
t.Errorf("expected critical severity, got: %s", cpolr.GetSeverities()[1])
}
})
t.Run("Results", func(t *testing.T) {
polr := &v1alpha2.PolicyReport{}
if s := len(polr.GetResults()); s != 0 {
t.Errorf("expected empty results, got: %d", s)
}
polr.SetResults([]v1alpha2.PolicyReportResult{
{Policy: "require-label", Result: v1alpha2.StatusPass},
})
if s := len(polr.GetResults()); s != 1 {
t.Errorf("expected 1 result, got: %d", s)
}
})
t.Run("Summary", func(t *testing.T) {
polr := &v1alpha2.PolicyReport{Summary: v1alpha2.PolicyReportSummary{Pass: 1}}
if s := polr.GetSummary().Pass; s != 1 {
t.Errorf("expected 1 pass result, got: %d", s)
}
})
}

View file

@ -1,45 +0,0 @@
package v1alpha2
import (
"github.com/kyverno/policy-reporter/pkg/helper"
)
func Extract(polr ReportInterface, cb func(res PolicyReportResult) string) []string {
list := make([]string, 0)
for _, k := range polr.GetResults() {
val := cb(k)
if val == "" || helper.Contains(val, list) {
continue
}
list = append(list, string(k.Severity))
}
return list
}
func ExtractPolicies(polr ReportInterface) []string {
return Extract(polr, func(res PolicyReportResult) string { return res.Policy })
}
func ExtractRules(polr ReportInterface) []string {
return Extract(polr, func(res PolicyReportResult) string { return res.Rule })
}
func ExtractSeverities(polr ReportInterface) []string {
return Extract(polr, func(res PolicyReportResult) string { return string(res.Severity) })
}
func ExtractCategories(polr ReportInterface) []string {
return Extract(polr, func(res PolicyReportResult) string { return res.Category })
}
func ExtractKinds(polr ReportInterface) []string {
return Extract(polr, func(res PolicyReportResult) string {
if res.HasResource() {
return res.GetResource().Kind
}
return ""
})
}