forked from guregu/mogi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
43 lines (34 loc) · 1.09 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
package mogi_test
import (
"testing"
"github.com/guregu/mogi"
)
func TestDelete(t *testing.T) {
defer mogi.Reset()
db := openDB()
mogi.Delete().StubRowsAffected(1)
_, err := db.Exec("DELETE FROM beer WHERE id = ?", 42)
checkNil(t, err)
mogi.Reset()
mogi.Delete().Table("beer").StubRowsAffected(1)
_, err = db.Exec("DELETE FROM beer WHERE id = ?", 42)
checkNil(t, err)
mogi.Reset()
mogi.Delete().Table("beer").Where("id", 42).StubRowsAffected(1)
_, err = db.Exec("DELETE FROM beer WHERE id = ?", 42)
checkNil(t, err)
mogi.Reset()
mogi.Delete().Table("beer").WhereOp("id", "=", 42).StubRowsAffected(1)
_, err = db.Exec("DELETE FROM beer WHERE id = ?", 42)
checkNil(t, err)
mogi.Reset()
mogi.Delete().Table("beer").WhereOp("id", "=", 42).WhereOp("id", ">", 100).StubRowsAffected(1)
_, err = db.Exec("DELETE FROM beer WHERE id = ? OR id > 100", 42)
checkNil(t, err)
mogi.Reset()
mogi.Delete().Table("beer").Where("id", 50).StubRowsAffected(1)
_, err = db.Exec("DELETE FROM beer WHERE id = ?", 42)
if err != mogi.ErrUnstubbed {
t.Error("err should be ErrUnstubbed but is", err)
}
}