2022-10-07 09:05:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/aquasecurity/table"
|
|
|
|
|
2024-02-23 15:05:01 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/emoji"
|
2022-10-17 07:24:07 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/hubtest"
|
2022-10-07 09:05:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func hubTestResultTable(out io.Writer, testResult map[string]bool) {
|
|
|
|
t := newLightTable(out)
|
|
|
|
t.SetHeaders("Test", "Result")
|
|
|
|
t.SetHeaderAlignment(table.AlignLeft)
|
|
|
|
t.SetAlignment(table.AlignLeft)
|
|
|
|
|
|
|
|
for testName, success := range testResult {
|
2024-02-23 15:05:01 +00:00
|
|
|
status := emoji.CheckMarkButton
|
2022-10-07 09:05:35 +00:00
|
|
|
if !success {
|
2024-02-23 15:05:01 +00:00
|
|
|
status = emoji.CrossMark
|
2022-10-07 09:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.AddRow(testName, status)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Render()
|
|
|
|
}
|
|
|
|
|
2022-10-17 07:24:07 +00:00
|
|
|
func hubTestListTable(out io.Writer, tests []*hubtest.HubTestItem) {
|
2022-10-07 09:05:35 +00:00
|
|
|
t := newLightTable(out)
|
|
|
|
t.SetHeaders("Name", "Path")
|
|
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft)
|
|
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft)
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.AddRow(test.Name, test.Path)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Render()
|
|
|
|
}
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
func hubTestParserCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
|
2022-10-07 09:05:35 +00:00
|
|
|
t := newLightTable(out)
|
|
|
|
t.SetHeaders("Parser", "Status", "Number of tests")
|
|
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
2023-12-07 11:21:04 +00:00
|
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
|
|
|
|
parserTested := 0
|
|
|
|
|
|
|
|
for _, test := range coverage {
|
2024-02-23 15:05:01 +00:00
|
|
|
status := emoji.RedCircle
|
2023-12-07 11:21:04 +00:00
|
|
|
if test.TestsCount > 0 {
|
2024-02-23 15:05:01 +00:00
|
|
|
status = emoji.GreenCircle
|
2023-12-07 11:21:04 +00:00
|
|
|
parserTested++
|
|
|
|
}
|
2024-02-23 15:05:01 +00:00
|
|
|
|
2023-12-07 11:21:04 +00:00
|
|
|
t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Render()
|
|
|
|
}
|
|
|
|
|
|
|
|
func hubTestAppsecRuleCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
|
|
|
|
t := newLightTable(out)
|
|
|
|
t.SetHeaders("Appsec Rule", "Status", "Number of tests")
|
|
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
2022-10-07 09:05:35 +00:00
|
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
|
|
|
|
parserTested := 0
|
2023-11-24 14:57:32 +00:00
|
|
|
|
2022-10-07 09:05:35 +00:00
|
|
|
for _, test := range coverage {
|
2024-02-23 15:05:01 +00:00
|
|
|
status := emoji.RedCircle
|
2022-10-07 09:05:35 +00:00
|
|
|
if test.TestsCount > 0 {
|
2024-02-23 15:05:01 +00:00
|
|
|
status = emoji.GreenCircle
|
2022-10-07 09:05:35 +00:00
|
|
|
parserTested++
|
|
|
|
}
|
2024-02-23 15:05:01 +00:00
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
|
2022-10-07 09:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Render()
|
|
|
|
}
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
func hubTestScenarioCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
|
2022-10-07 09:05:35 +00:00
|
|
|
t := newLightTable(out)
|
|
|
|
t.SetHeaders("Scenario", "Status", "Number of tests")
|
|
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
|
|
|
|
parserTested := 0
|
2023-11-24 14:57:32 +00:00
|
|
|
|
2022-10-07 09:05:35 +00:00
|
|
|
for _, test := range coverage {
|
2024-02-23 15:05:01 +00:00
|
|
|
status := emoji.RedCircle
|
2022-10-07 09:05:35 +00:00
|
|
|
if test.TestsCount > 0 {
|
2024-02-23 15:05:01 +00:00
|
|
|
status = emoji.GreenCircle
|
2022-10-07 09:05:35 +00:00
|
|
|
parserTested++
|
|
|
|
}
|
2024-02-23 15:05:01 +00:00
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
|
2022-10-07 09:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Render()
|
|
|
|
}
|