forked from quintush/helm-unittest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
assertion_result.go
54 lines (48 loc) · 1.19 KB
/
assertion_result.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
package unittest
import "fmt"
// AssertionResult result return by Assertion.Assert
type AssertionResult struct {
Index int
FailInfo []string
Passed bool
AssertType string
Not bool
CustomInfo string
}
func (ar AssertionResult) print(printer *Printer, verbosity int) {
if ar.Passed {
return
}
var title string
if ar.CustomInfo != "" {
title = ar.CustomInfo
} else {
var notAnnotation string
if ar.Not {
notAnnotation = " NOT"
}
title = fmt.Sprintf("- asserts[%d]%s `%s` fail", ar.Index, notAnnotation, ar.AssertType)
}
printer.println(printer.danger(title+"\n"), 2)
for _, infoLine := range ar.FailInfo {
printer.println(infoLine, 3)
}
printer.println("", 0)
}
// ToString writing the object to a customized formatted string.
func (ar AssertionResult) stringify() string {
content := ""
if ar.CustomInfo != "" {
content += fmt.Sprintf("\t\t %s \n", ar.CustomInfo)
} else {
var notAnnotation string
if ar.Not {
notAnnotation = " NOT"
}
content += fmt.Sprintf("\t\t - asserts[%d]%s `%s` fail \n", ar.Index, notAnnotation, ar.AssertType)
}
for _, infoLine := range ar.FailInfo {
content += fmt.Sprintf("\t\t\t %s \n", infoLine)
}
return content
}