-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdelete_test.go
41 lines (30 loc) · 941 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
package dat
import (
"testing"
"gopkg.in/stretchr/testify.v1/assert"
)
func BenchmarkDeleteSql(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
DeleteFrom("alpha").Where("a = $1", "b").ToSQL()
}
}
func TestDeleteAllToSql(t *testing.T) {
sql, _ := DeleteFrom("a").ToSQL()
assert.Equal(t, sql, "DELETE FROM a")
}
func TestDeleteSingleToSql(t *testing.T) {
sql, args := DeleteFrom("a").Where("id = $1", 1).ToSQL()
assert.Equal(t, sql, "DELETE FROM a WHERE (id = $1)")
assert.Equal(t, args, []interface{}{1})
}
func TestDeleteTenStaringFromTwentyToSql(t *testing.T) {
sql, _ := DeleteFrom("a").ToSQL()
assert.Equal(t, sql, "DELETE FROM a")
}
func TestDeleteWhereExprSql(t *testing.T) {
expr := Expr("id=$1", 100)
sql, args := DeleteFrom("a").Where("foo = $1", "bar").Where(expr).ToSQL()
assert.Equal(t, sql, `DELETE FROM a WHERE (foo = $1) AND (id=$2)`)
assert.Exactly(t, args, []interface{}{"bar", 100})
}