-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathreport.go
47 lines (39 loc) · 947 Bytes
/
report.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
package lib
import (
"fmt"
)
type Report struct {
passed []string
failed []string
}
//Passed case
func (r *Report) Passed(caseName string) {
r.passed = append(r.passed, fmt.Sprintf("%s: [%s]", caseName, "PASSED"))
}
//Failed case
func (r *Report) Failed(caseName string, err error) {
errMsg := ""
if err != nil {
errMsg = err.Error()
}
r.failed = append(r.failed, fmt.Sprintf("%s: [%s] %s", caseName, "FAILED", errMsg))
}
//Print report
func (r *Report) Print() {
passed := len(r.passed)
failed := len(r.failed)
total := passed + failed
fmt.Println("=====================================")
fmt.Printf("Overall: %d/%d passed , %d/%d failed\n", passed, total, failed, total)
fmt.Println("=====================================")
for _, res := range r.passed {
fmt.Println(res)
}
for _, res := range r.failed {
fmt.Println(res)
}
}
//IsFail : Overall result
func (r *Report) IsFail() bool {
return len(r.failed) > 0
}