-
Notifications
You must be signed in to change notification settings - Fork 6
/
delete_test.go
68 lines (61 loc) · 1.52 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package memeduck_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/genkami/memeduck"
)
func testDelete(t *testing.T, stmt *memeduck.DeleteStmt, expected string) {
actual, err := stmt.SQL()
assert.Nil(t, err, expected)
assert.Equal(t, expected, actual)
}
func TestDelete(t *testing.T) {
testDelete(t,
memeduck.Delete("hoge").Where(
memeduck.Bool(true),
),
`DELETE FROM hoge WHERE TRUE`,
)
testDelete(t,
memeduck.Delete("hoge").Where(
memeduck.Eq(1, 2),
),
`DELETE FROM hoge WHERE 1 = 2`,
)
testDelete(t,
memeduck.Delete("hoge").Where(
memeduck.Ne(memeduck.Ident("a"), "foo"),
),
`DELETE FROM hoge WHERE a != "foo"`,
)
testDelete(t,
memeduck.Delete("hoge").Where(
memeduck.Eq(memeduck.Ident("a"), 1),
memeduck.Eq(memeduck.Ident("b"), "2"),
),
`DELETE FROM hoge WHERE a = 1 AND b = "2"`,
)
testDelete(t,
memeduck.Delete("hoge").Where(
memeduck.Eq(memeduck.Ident("a"), 1),
memeduck.Eq(memeduck.Ident("b"), "2"),
memeduck.Ne(memeduck.Ident("c"), []byte{3}),
),
`DELETE FROM hoge WHERE a = 1 AND b = "2" AND c != B"\x03"`,
)
}
func TestDeleteWithMultipleWhereClause(t *testing.T) {
testDelete(t,
memeduck.Delete("hoge").Where(
memeduck.Eq(memeduck.Ident("a"), 1),
).Where(
memeduck.Eq(memeduck.Ident("b"), "2"),
memeduck.Ne(memeduck.Ident("c"), []byte{3}),
),
`DELETE FROM hoge WHERE a = 1 AND b = "2" AND c != B"\x03"`,
)
}
func TestDeleteWithNoWhereClause(t *testing.T) {
_, err := memeduck.Delete("hoge").SQL()
assert.Error(t, err)
}