nuclei/v2/cmd/integration-test/integration-test.go

55 lines
1.3 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"strings"
"github.com/logrusorgru/aurora"
2021-02-26 20:53:06 +00:00
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
)
var (
debug = os.Getenv("DEBUG") == "true"
customTest = os.Getenv("TEST")
2021-02-26 20:53:06 +00:00
protocol = os.Getenv("PROTO")
errored = false
)
func main() {
success := aurora.Green("[✓]").String()
failed := aurora.Red("[✘]").String()
2021-02-26 20:53:06 +00:00
protocolTests := map[string]map[string]testutils.TestCase{
"http": httpTestcases,
"network": networkTestcases,
"dns": dnsTestCases,
"workflow": workflowTestcases,
2021-02-26 20:53:06 +00:00
}
for proto, tests := range protocolTests {
if protocol == "" || protocol == proto {
fmt.Printf("Running test cases for \"%s\" protocol\n", aurora.Blue(proto))
for file, test := range tests {
if customTest != "" && !strings.Contains(file, customTest) {
continue // only run tests user asked
}
if err := test.Execute(file); err != nil {
2021-02-26 20:53:06 +00:00
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, file, err)
errored = true
2021-02-26 20:53:06 +00:00
} else {
fmt.Printf("%s Test \"%s\" passed!\n", success, file)
}
}
}
}
if errored {
os.Exit(1)
}
}
func errIncorrectResultsCount(results []string) error {
return fmt.Errorf("incorrect number of results %s", strings.Join(results, "\n\t"))
}