forked from goss-org/goss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tap.go
53 lines (42 loc) · 1.13 KB
/
tap.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
package outputs
import (
"fmt"
"io"
"strconv"
"time"
"github.com/aelsabbahy/goss/resource"
)
type Tap struct{}
func (r Tap) Output(w io.Writer, results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
testCount := 0
failed := 0
var summary map[int]string
summary = make(map[int]string)
for resultGroup := range results {
for _, testResult := range resultGroup {
switch testResult.Result {
case resource.SUCCESS:
summary[testCount] = "ok " + strconv.Itoa(testCount+1) + " - " + humanizeResult2(testResult) + "\n"
case resource.FAIL:
summary[testCount] = "not ok " + strconv.Itoa(testCount+1) + " - " + humanizeResult2(testResult) + "\n"
failed++
case resource.SKIP:
summary[testCount] = "ok " + strconv.Itoa(testCount+1) + " - # SKIP " + humanizeResult2(testResult) + "\n"
default:
panic(fmt.Sprintf("Unexpected Result Code: %v\n", testResult.Result))
}
testCount++
}
}
fmt.Fprintf(w, "1..%d\n", testCount)
for i := 0; i < testCount; i++ {
fmt.Fprintf(w, "%s", summary[i])
}
if failed > 0 {
return 1
}
return 0
}
func init() {
RegisterOutputer("tap", &Tap{})
}