-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdelete_all_test.go
137 lines (109 loc) · 3.25 KB
/
delete_all_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package reltest
import (
"context"
"database/sql"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDeleteAll(t *testing.T) {
var (
repo = New()
)
repo.ExpectDeleteAll().For(&[]Book{{ID: 1}}).Success()
assert.Nil(t, repo.DeleteAll(context.TODO(), &[]Book{{ID: 1}}))
repo.AssertExpectations(t)
repo.ExpectDeleteAll().For(&[]Book{{ID: 1}}).Success()
assert.NotPanics(t, func() {
repo.MustDeleteAll(context.TODO(), &[]Book{{ID: 1}})
})
repo.AssertExpectations(t)
}
func TestDeleteAll_ForType(t *testing.T) {
var (
repo = New()
)
repo.ExpectDeleteAll().ForType("[]reltest.Book")
assert.Nil(t, repo.DeleteAll(context.TODO(), &[]Book{{ID: 1}}))
repo.AssertExpectations(t)
repo.ExpectDeleteAll().ForType("[]reltest.Book")
assert.NotPanics(t, func() {
repo.MustDeleteAll(context.TODO(), &[]Book{{ID: 1}})
})
repo.AssertExpectations(t)
}
func TestDeleteAll_ForTable(t *testing.T) {
var (
repo = New()
)
repo.ExpectDeleteAll().ForTable("books")
assert.Nil(t, repo.DeleteAll(context.TODO(), &[]Book{{ID: 1}}))
repo.AssertExpectations(t)
repo.ExpectDeleteAll().ForTable("books")
assert.NotPanics(t, func() {
repo.MustDeleteAll(context.TODO(), &[]Book{{ID: 1}})
})
repo.AssertExpectations(t)
}
func TestDeleteAll_error(t *testing.T) {
var (
repo = New()
)
repo.ExpectDeleteAll().ConnectionClosed()
assert.Equal(t, sql.ErrConnDone, repo.DeleteAll(context.TODO(), &[]Book{{ID: 1}}))
repo.AssertExpectations(t)
repo.ExpectDeleteAll().ConnectionClosed()
assert.Panics(t, func() {
repo.MustDeleteAll(context.TODO(), &[]Book{{ID: 1}})
})
repo.AssertExpectations(t)
}
func TestDeleteAll_assertFor(t *testing.T) {
var (
repo = New()
)
repo.ExpectDeleteAll().For(&[]Book{{ID: 1}})
assert.Panics(t, func() {
repo.DeleteAll(context.TODO(), &[]Book{{ID: 2}})
})
assert.False(t, repo.AssertExpectations(nt))
assert.Equal(t, "FAIL: Mock defined but not called:\nDeleteAll(ctx, &[]reltest.Book{reltest.Book{ID: 1}})", nt.lastLog)
}
func TestDeleteAll_assertForTable(t *testing.T) {
var (
repo = New()
)
repo.ExpectDeleteAll().ForTable("users")
assert.Panics(t, func() {
repo.DeleteAll(context.TODO(), &[]Book{})
})
assert.False(t, repo.AssertExpectations(nt))
assert.Equal(t, "FAIL: Mock defined but not called:\nDeleteAll(ctx, <Table: users>)", nt.lastLog)
}
func TestDeleteAll_assertForType(t *testing.T) {
var (
repo = New()
)
repo.ExpectDeleteAll().ForType("[]User")
assert.Panics(t, func() {
repo.DeleteAll(context.TODO(), &[]Book{})
})
assert.False(t, repo.AssertExpectations(nt))
assert.Equal(t, "FAIL: Mock defined but not called:\nDeleteAll(ctx, <Type: *[]User>)", nt.lastLog)
}
func TestDeleteAll_assert_transaction(t *testing.T) {
var (
repo = New()
)
repo.ExpectTransaction(func(repo *Repository) {
repo.ExpectDeleteAll().ForType("[]User")
})
assert.False(t, repo.AssertExpectations(nt))
assert.Equal(t, "FAIL: Mock defined but not called:\n<Transaction: 1> DeleteAll(ctx, <Type: *[]User>)", nt.lastLog)
}
func TestDeleteAll_String(t *testing.T) {
var (
mockDeleteAll = MockDeleteAll{assert: &Assert{}, argEntity: &[]Book{}}
)
assert.Equal(t, `DeleteAll(ctx, &[]reltest.Book{})`, mockDeleteAll.String())
assert.Equal(t, `ExpectDeleteAll().ForType("*[]reltest.Book")`, mockDeleteAll.ExpectString())
}