-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert_error.go
56 lines (48 loc) · 1.37 KB
/
assert_error.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
55
56
package actually
import (
"testing"
)
// NoError(t) method asserts that an error you got is NOt kind of error.
// Actually, this assertion is mostly same as Nil(t). But fail report of NoError(t) is helpful for a type of error.
/*
g, err := someFunc()
actually.GotError(err).NoError(t)
*/
// These are almost same as above code and below one.
/*
g, err := someFunc()
actually.Got(err).NoError(t)
*/
// Got(any) can accept any type of value, but GotError(error) can accept ONLY a type of error.
// It's more strict when you use GotError(error) to test a type of error.
func (a *testingA) NoError(t *testing.T, testNames ...string) *testingA {
invalidCall(a)
a.name = a.naming(testNames...)
a.t = t
a.t.Helper()
if a.got != nil {
var reason string
wi := a.wi().Got(a.got)
if !a.isTypeOfError() {
reason = reason_WrongType
wi.Message(notice_Label, "It should be type of error")
} else {
reason = reason_UnexpectedlyError
wi.Message(notice_Label, "No error")
}
return a.fail(wi, reason)
}
return a
}
func (a *testingA) isTypeOfError() bool {
_, ok := a.got.(error)
return ok
}
// GotError sets the error value you actually got. GotError creates `*testingA` and returns it.
func GotError(g error) *testingA {
return Got(g)
}
// GotError on *testingA sets the error value you actually got.
func (a *testingA) GotError(g error) *testingA {
return a.Got(g)
}