-
-
Notifications
You must be signed in to change notification settings - Fork 191
/
assert.go
53 lines (50 loc) · 1.16 KB
/
assert.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 assert
type Equality struct {
// Message is the prefix message for the assersion
Message string
// Expected is the expected value for the assersion
Expected string
// Got is the actual value
Got string
// Continue used to determine weather or not to continue with further assertions.
IsEqual bool
}
func (e Equality) Error() string {
return e.Message + ", Expected " + e.Expected + " Got " + e.Got
}
func (e Equality) String() string { return e.Error() }
func ErrorEquality(expErr, gotErr error) Equality {
if expErr != gotErr {
// could be because test.err == nil and err != nil.
if expErr == nil && gotErr != nil {
return Equality{
"unexpected error",
"nil",
gotErr.Error(),
false,
}
}
if expErr != nil && gotErr == nil {
return Equality{
"expected error",
expErr.Error(),
"nil",
false,
}
}
if expErr.Error() != gotErr.Error() {
return Equality{
"incorrect error value",
expErr.Error(),
gotErr.Error(),
false,
}
}
return Equality{IsEqual: true}
}
if expErr != nil {
// No need to look at other values, expected an error.
return Equality{}
}
return Equality{IsEqual: true}
}