forked from go-rel/reltest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_test.go
84 lines (68 loc) · 1.91 KB
/
count_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package reltest
import (
"context"
"database/sql"
"testing"
"github.com/go-rel/rel"
"github.com/stretchr/testify/assert"
)
func TestCount(t *testing.T) {
var (
repo = New()
)
repo.ExpectCount("books").Result(2)
count, err := repo.Count(context.TODO(), "books")
assert.Nil(t, err)
assert.Equal(t, 2, count)
repo.AssertExpectations(t)
repo.ExpectCount("books").Result(2)
assert.NotPanics(t, func() {
count := repo.MustCount(context.TODO(), "books")
assert.Equal(t, 2, count)
})
repo.AssertExpectations(t)
}
func TestCount_error(t *testing.T) {
var (
repo = New()
)
repo.ExpectCount("books").ConnectionClosed()
count, err := repo.Count(context.TODO(), "books")
assert.Equal(t, sql.ErrConnDone, err)
assert.Equal(t, 0, count)
repo.AssertExpectations(t)
repo.ExpectCount("books").ConnectionClosed()
assert.Panics(t, func() {
count := repo.MustCount(context.TODO(), "books")
assert.Equal(t, 0, count)
})
repo.AssertExpectations(t)
}
func TestCount_assert(t *testing.T) {
var (
repo = New()
)
repo.ExpectCount("users")
assert.Panics(t, func() {
repo.Count(context.TODO(), "books")
})
assert.False(t, repo.AssertExpectations(nt))
assert.Equal(t, "FAIL: Mock defined but not called:\nCount(ctx, \"users\", rel.From(\"users\"))", nt.lastLog)
}
func TestCount_assert_transaction(t *testing.T) {
var (
repo = New()
)
repo.ExpectTransaction(func(repo *Repository) {
repo.ExpectCount("users")
})
assert.False(t, repo.AssertExpectations(nt))
assert.Equal(t, "FAIL: Mock defined but not called:\n<Transaction: 1> Count(ctx, \"users\", rel.From(\"users\"))", nt.lastLog)
}
func TestCount_String(t *testing.T) {
var (
mockCount = MockCount{assert: &Assert{}, argCollection: "users", argQuery: rel.From("users")}
)
assert.Equal(t, "Count(ctx, \"users\", rel.From(\"users\"))", mockCount.String())
assert.Equal(t, "ExpectCount(\"users\", rel.From(\"users\"))", mockCount.ExpectString())
}