forked from summerwind/h2spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h2spec.go
104 lines (83 loc) · 1.86 KB
/
h2spec.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package h2spec
import (
"fmt"
"time"
"github.com/summerwind/h2spec/client"
"github.com/summerwind/h2spec/config"
"github.com/summerwind/h2spec/generic"
"github.com/summerwind/h2spec/hpack"
"github.com/summerwind/h2spec/http2"
"github.com/summerwind/h2spec/log"
"github.com/summerwind/h2spec/reporter"
"github.com/summerwind/h2spec/spec"
)
func Run(c *config.Config) (bool, error) {
total := 0
success := true
specs := []*spec.TestGroup{
generic.Spec(),
http2.Spec(),
hpack.Spec(),
}
start := time.Now()
for _, s := range specs {
s.Test(c)
if s.FailedCount > 0 {
success = false
}
total += s.FailedCount
total += s.SkippedCount
total += s.PassedCount
}
end := time.Now()
d := end.Sub(start)
if c.DryRun {
return true, nil
}
if total == 0 {
log.SetIndentLevel(0)
log.Println("No matched tests found.")
return true, nil
}
if !success {
log.SetIndentLevel(0)
reporter.FailedTests(specs)
}
log.SetIndentLevel(0)
log.Println(fmt.Sprintf("Finished in %.4f seconds", d.Seconds()))
reporter.Summary(specs)
if c.JUnitReport != "" {
err := reporter.JUnitReport(specs, c.JUnitReport)
if err != nil {
return false, err
}
}
return success, nil
}
func RunClientSpec(c *config.Config) error {
s := client.Spec()
server, err := spec.Listen(c, s)
if err != nil {
return err
}
if !c.IsBrowserMode() {
start := time.Now()
s.Test(c)
end := time.Now()
d := end.Sub(start)
if s.FailedCount > 0 {
log.SetIndentLevel(0)
reporter.PrintFailedClientTests(s)
}
log.SetIndentLevel(0)
log.Println(fmt.Sprintf("Finished in %.4f seconds", d.Seconds()))
reporter.PrintSummaryForClient(s)
} else {
// Block running
log.Println("--exec is not defined, enable BROWSER mode")
reportServer := reporter.NewWebReportServer(c, s)
log.Println(reportServer.RunForever())
}
defer server.Close()
return nil
}