-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
53 lines (50 loc) · 998 Bytes
/
delete_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
package orm
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestDelerer_Build(t *testing.T) {
db := memoryDB(t)
testCases := []struct {
name string
q QueryBuilder
wantQuery *Query
wantErr error
}{
{
// From 都不调用
name: "no from",
q: NewDeleter[TestModel](db),
wantQuery: &Query{
SQL: "DELETE FROM `test_model`;",
},
},
{
// 调用 FROM
name: "with from",
q: NewDeleter[TestModel](db).From("`test_model_t`"),
wantQuery: &Query{
SQL: "DELETE FROM `test_model_t`;",
},
},
{
// WHERE
name: "where",
q: NewDeleter[TestModel](db).Where(C("Id").EQ(16)),
wantQuery: &Query{
SQL: "DELETE FROM `test_model` WHERE `id` = ?;",
Args: []any{16},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
query, err := tc.q.Build()
assert.Equal(t, tc.wantErr, err)
if err != nil {
return
}
assert.Equal(t, tc.wantQuery, query)
})
}
}