-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration-test.go
57 lines (48 loc) · 1.3 KB
/
integration-test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"os"
"strings"
"github.com/logrusorgru/aurora"
"github.com/projectdiscovery/httpx/internal/testutils"
)
var (
debug = os.Getenv("DEBUG") == "true"
customTest = os.Getenv("TEST")
protocol = os.Getenv("PROTO")
errored = false
)
func main() {
success := aurora.Green("[✓]").String()
failed := aurora.Red("[✘]").String()
tests := map[string]map[string]testutils.TestCase{
"http": httpTestcases,
"library": libraryTestcases,
}
for proto, tests := range tests {
if protocol == "" || protocol == proto {
fmt.Printf("Running test cases for \"%s\"\n", aurora.Blue(proto))
for name, test := range tests {
if customTest != "" && !strings.Contains(name, customTest) {
continue // only run tests user asked
}
err := test.Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, name, err)
errored = true
} else {
fmt.Printf("%s Test \"%s\" passed!\n", success, name)
}
}
}
}
if errored {
os.Exit(1)
}
}
func errIncorrectResultsCount(results []string) error {
return fmt.Errorf("incorrect number of results %s", strings.Join(results, "\n\t"))
}
func errIncorrectResult(expected, got string) error {
return fmt.Errorf("incorrect result: expected \"%s\" got \"%s\"", expected, got)
}