mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-13 05:15:58 +02:00
lint/nestif: reduce hubtest complexity (#3244)
This commit is contained in:
parent
29f3d2710d
commit
00032d40a8
2 changed files with 43 additions and 25 deletions
|
@ -27,7 +27,7 @@ linters-settings:
|
||||||
|
|
||||||
nestif:
|
nestif:
|
||||||
# lower this after refactoring
|
# lower this after refactoring
|
||||||
min-complexity: 19
|
min-complexity: 16
|
||||||
|
|
||||||
nlreturn:
|
nlreturn:
|
||||||
block-size: 5
|
block-size: 5
|
||||||
|
|
|
@ -56,6 +56,46 @@ func (cli *cliHubTest) run(runAll bool, nucleiTargetHost string, appSecHost stri
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printParserFailures(test *hubtest.HubTestItem) {
|
||||||
|
if len(test.ParserAssert.Fails) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
log.Errorf("Parser test '%s' failed (%d errors)\n", test.Name, len(test.ParserAssert.Fails))
|
||||||
|
|
||||||
|
for _, fail := range test.ParserAssert.Fails {
|
||||||
|
fmt.Printf("(L.%d) %s => %s\n", fail.Line, emoji.RedCircle, fail.Expression)
|
||||||
|
fmt.Printf(" Actual expression values:\n")
|
||||||
|
|
||||||
|
for key, value := range fail.Debug {
|
||||||
|
fmt.Printf(" %s = '%s'\n", key, strings.TrimSuffix(value, "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func printScenarioFailures(test *hubtest.HubTestItem) {
|
||||||
|
if len(test.ScenarioAssert.Fails) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
log.Errorf("Scenario test '%s' failed (%d errors)\n", test.Name, len(test.ScenarioAssert.Fails))
|
||||||
|
|
||||||
|
for _, fail := range test.ScenarioAssert.Fails {
|
||||||
|
fmt.Printf("(L.%d) %s => %s\n", fail.Line, emoji.RedCircle, fail.Expression)
|
||||||
|
fmt.Printf(" Actual expression values:\n")
|
||||||
|
|
||||||
|
for key, value := range fail.Debug {
|
||||||
|
fmt.Printf(" %s = '%s'\n", key, strings.TrimSuffix(value, "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (cli *cliHubTest) newRunCmd() *cobra.Command {
|
func (cli *cliHubTest) newRunCmd() *cobra.Command {
|
||||||
var (
|
var (
|
||||||
noClean bool
|
noClean bool
|
||||||
|
@ -111,30 +151,8 @@ func (cli *cliHubTest) newRunCmd() *cobra.Command {
|
||||||
success = false
|
success = false
|
||||||
cleanTestEnv := false
|
cleanTestEnv := false
|
||||||
if cfg.Cscli.Output == "human" {
|
if cfg.Cscli.Output == "human" {
|
||||||
if len(test.ParserAssert.Fails) > 0 {
|
printParserFailures(test)
|
||||||
fmt.Println()
|
printScenarioFailures(test)
|
||||||
log.Errorf("Parser test '%s' failed (%d errors)\n", test.Name, len(test.ParserAssert.Fails))
|
|
||||||
for _, fail := range test.ParserAssert.Fails {
|
|
||||||
fmt.Printf("(L.%d) %s => %s\n", fail.Line, emoji.RedCircle, fail.Expression)
|
|
||||||
fmt.Printf(" Actual expression values:\n")
|
|
||||||
for key, value := range fail.Debug {
|
|
||||||
fmt.Printf(" %s = '%s'\n", key, strings.TrimSuffix(value, "\n"))
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(test.ScenarioAssert.Fails) > 0 {
|
|
||||||
fmt.Println()
|
|
||||||
log.Errorf("Scenario test '%s' failed (%d errors)\n", test.Name, len(test.ScenarioAssert.Fails))
|
|
||||||
for _, fail := range test.ScenarioAssert.Fails {
|
|
||||||
fmt.Printf("(L.%d) %s => %s\n", fail.Line, emoji.RedCircle, fail.Expression)
|
|
||||||
fmt.Printf(" Actual expression values:\n")
|
|
||||||
for key, value := range fail.Debug {
|
|
||||||
fmt.Printf(" %s = '%s'\n", key, strings.TrimSuffix(value, "\n"))
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !forceClean && !noClean {
|
if !forceClean && !noClean {
|
||||||
prompt := &survey.Confirm{
|
prompt := &survey.Confirm{
|
||||||
Message: fmt.Sprintf("\nDo you want to remove runtime folder for test '%s'? (default: Yes)", test.Name),
|
Message: fmt.Sprintf("\nDo you want to remove runtime folder for test '%s'? (default: Yes)", test.Name),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue