forked from chuckpreslar/codex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_manager_test.go
More file actions
64 lines (51 loc) · 1.44 KB
/
insert_manager_test.go
File metadata and controls
64 lines (51 loc) · 1.44 KB
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
package codex
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestInsertManager(t *testing.T) {
relation := Table("table")
mgr := Insertion(relation)
// The following struct members should exist.
_ = mgr.Tree
// The following receiver methods should exist.
_ = mgr.Insert(1)
_ = mgr.Into(1)
_ = mgr.Returning(1)
_, _, _ = mgr.ToSql()
}
func TestInsertManagerInsert(t *testing.T) {
tlb := Table("users")
mgr := Insertion(tlb)
sql, args, err := mgr.Insert("john", "doe", "33").Into("first_name", "last_name", "age").ToSql()
assert.Nil(t, err)
assert.Equal(t, `INSERT INTO "users" ("first_name","last_name","age") VALUES (?,?,?)`, sql)
assert.Equal(t, []interface{}{"john", "doe", "33"}, args)
}
func TestInsertManagerSelection(t *testing.T) {
users := Table("users")
mgr := Insertion(users)
sel := mgr.Selection()
sql, args, err := sel.ToSql()
assert.Nil(t, err)
assert.Equal(t, `SELECT "users".* FROM "users"`, sql)
assert.Empty(t, args)
}
func TestInsertManagerModification(t *testing.T) {
users := Table("users")
mgr := Insertion(users)
mod := mgr.Modification()
sql, args, err := mod.ToSql()
assert.Nil(t, err)
assert.Equal(t, `UPDATE "users" `, sql)
assert.Empty(t, args)
}
func TestInsertManagerDeletion(t *testing.T) {
users := Table("users")
mgr := Insertion(users)
mod := mgr.Deletion()
sql, args, err := mod.ToSql()
assert.Nil(t, err)
assert.Equal(t, `DELETE FROM "users" `, sql)
assert.Empty(t, args)
}