forked from stfsy/golang-assert
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
66 lines (53 loc) · 1.5 KB
/
example_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
63
64
65
66
package golangassert
import (
"os"
"testing"
"github.com/vizor-games/golang-unittest/assert"
"github.com/vizor-games/golang-unittest/check"
)
type Person struct {
name string
age int
}
var paul = Person{
name: "Paul",
age: 32,
}
var peter = Person{
name: "Peter",
age: 21,
}
func TestEqual(t *testing.T) {
assert.Equal(t, paul, paul, "Paul equals Paul")
check.Equal(t, paul, paul, "Paul equals Paul")
}
func TestNotEqual(t *testing.T) {
assert.NotEqual(t, paul, peter, "Paul does not equal Peter")
check.NotEqual(t, paul, peter, "Paul does not equal Peter")
}
func TestNotEqualNil(t *testing.T) {
assert.NotEqual(t, paul, nil, "Paul is not nil")
check.NotEqual(t, paul, nil, "Paul is not nil")
}
func TestNilEqualNil(t *testing.T) {
assert.Equal(t, nil, nil, "Nil is nil")
check.Equal(t, nil, nil, "Nil is nil")
}
func TestIn(t *testing.T) {
assert.In(t, "Paul does not equal Peter", "Paul", "Paul is substring of message")
check.In(t, "Paul does not equal Peter", "Paul", "Paul is substring of message")
}
func TestError(t *testing.T) {
// "err is not nil for unexist file"
assert.Error(t, assert.J(os.Open("unexist.file")))
check.Error(t, check.J(os.Open("unexist.file")))
}
func TestNilError(t *testing.T) {
assert.NilError(t, assert.J(os.OpenFile("tempfile.txt", os.O_RDWR|os.O_CREATE, 0755)))
check.NilError(t, check.J(os.OpenFile("tempfile.txt", os.O_RDWR|os.O_CREATE, 0755)))
os.Remove("tempfile.txt")
}
func TestNilErr(t *testing.T) {
assert.NilErr(t, nil)
check.NilErr(t, nil)
}