-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert_error_test.go
62 lines (52 loc) · 1.49 KB
/
assert_error_test.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
57
58
59
60
61
62
package actually
import (
"os"
"testing"
)
const existingFileInThisModule = "README.md"
const notexistingFileInThisModule = "not-found-01xt79a5jk.exe"
func TestNoError(t *testing.T) {
_, err := os.Open(existingFileInThisModule)
Got(err).NoError(t)
}
func TestNoError_Fail(t *testing.T) {
stubConfirm(t, func() {
_, err := os.Open(notexistingFileInThisModule)
Got(err).NoError(t)
}, reason_UnexpectedlyError)
}
func TestIsTypeOfError(t *testing.T) {
if Got(123).isTypeOfError() != false {
t.Error("Integer should NOT be a type of error")
}
_, err := os.Open(notexistingFileInThisModule)
if Got(err).isTypeOfError() != true {
t.Errorf("%#v should be a type of error", err)
}
}
func TestGotError(t *testing.T) {
_, err := os.Open(notexistingFileInThisModule)
a := GotError(err)
if a.got != err {
t.Errorf("`GotError()` was broken. Expected:%#v, but Actual:%#v", err, a.got)
}
_, err2 := os.Open(existingFileInThisModule)
a2 := GotError(err2)
if a2.got != err2 {
t.Errorf("`GotError()` was broken. Expected:%#v, but Actual:%#v", err2, a2.got)
}
}
func TestActuallyGotError(t *testing.T) {
_, err := os.Open(notexistingFileInThisModule)
a := &testingA{}
a.GotError(err)
if a.got != err {
t.Errorf("`actually.GotError()` was broken. Expected:%#v, but Actual:%#v", err, a.got)
}
_, err2 := os.Open(existingFileInThisModule)
a2 := &testingA{}
a2.GotError(err2)
if a2.got != err2 {
t.Errorf("`actually.GotError()` was broken. Expected:%#v, but Actual:%#v", err2, a2.got)
}
}