forked from tikv/client-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
152 lines (136 loc) · 3.67 KB
/
main.go
File metadata and controls
152 lines (136 loc) · 3.67 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"encoding/json"
"flag"
"fmt"
"strings"
"github.com/logrusorgru/aurora"
_ "github.com/tikv/client-validator/tests" // import tests
"github.com/tikv/client-validator/validator"
)
var (
showRecord = flag.String("record", "failed", "none | failed | all")
showLog = flag.Bool("show-log", false, "show test logs in report")
outputStyle = flag.String("output", "console", "console | text | json")
)
func main() {
flag.Parse()
report := validator.RunAll()
trimReport(&report)
printReport(&report)
}
func trimReport(report *validator.Report) {
for i := range report.Stories {
for j := range report.Stories[i].Features {
trimFeatureReport(&report.Stories[i].Features[j])
}
}
for i := range report.Features {
trimFeatureReport(&report.Features[i])
}
}
func trimFeatureReport(report *validator.FeatureReport) {
records := report.Records[:0]
for _, r := range report.Records {
if *showRecord == "all" || (*showRecord == "failed" && !r.Success) {
if !*showLog {
r.Logs = nil
}
records = append(records, r)
}
}
report.Records = records
}
func printReport(report *validator.Report) {
switch *outputStyle {
case "json":
printJSON(report)
case "text":
printText(report)
default:
printConsole(report)
}
}
func printJSON(report *validator.Report) {
data, _ := json.MarshalIndent(report, "", " ")
fmt.Println(string(data))
}
func printText(report *validator.Report) {
hr := strings.Repeat("-", 80)
printFeature := func(feature *validator.FeatureReport) {
fmt.Printf(" + [%v] %v: %v\n", feature.Status, feature.Key, feature.Description)
for _, r := range feature.Records {
stateText := "PASS"
if !r.Success {
stateText = "FAIL"
}
fmt.Printf(" - [%v] %v\n", stateText, r.Description)
for _, l := range r.Logs {
fmt.Printf(" $ %s\n", l)
}
}
}
for _, s := range report.Stories {
fmt.Println(hr)
fmt.Println("# " + s.Description)
for _, feature := range s.Features {
printFeature(&feature)
}
}
for _, feature := range report.Features {
fmt.Println(hr)
printFeature(&feature)
}
}
func printConsole(report *validator.Report) {
hr := strings.Repeat("-", 80)
printFeature := func(feature *validator.FeatureReport) {
info := aurora.Bold(aurora.Blue(fmt.Sprintf("%s: %s", feature.Key, feature.Description)))
fmt.Printf(" [%v] %v\n", colorizeStatus(string(feature.Status)), info)
for _, r := range feature.Records {
stateText := "PASS"
if !r.Success {
stateText = "FAIL"
}
fmt.Printf(" [%v] %v\n", colorizeStatus(stateText), aurora.Bold(aurora.Cyan(r.Description)))
for _, l := range r.Logs {
fmt.Print(" ")
fmt.Println(aurora.Gray(8, l))
}
}
}
for _, s := range report.Stories {
fmt.Println(hr)
fmt.Println(aurora.Bold(aurora.Magenta("# " + s.Description)))
for _, feature := range s.Features {
printFeature(&feature)
}
}
for _, feature := range report.Features {
fmt.Println(hr)
printFeature(&feature)
}
}
func colorizeStatus(text string) aurora.Value {
switch text {
case "PASS":
return aurora.Green(text)
case "NOT_IMPL", "SKIP":
return aurora.Gray(8, text)
case "FAIL", "DEFECT":
return aurora.Red(text)
}
return nil
}