-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstruct_mapping_test.go
44 lines (36 loc) · 960 Bytes
/
struct_mapping_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
package dat
import (
"testing"
"gopkg.in/stretchr/testify.v1/assert"
)
func TestEmbeddedStructMapping(t *testing.T) {
type Realm struct {
RealmUUID string `db:"realm_uuid"`
}
type Group struct {
GroupUUID string `db:"group_uuid"`
*Realm
}
g := &Group{Realm: &Realm{"11"}, GroupUUID: "22"}
sql, args := InsertInto("groups").Columns("group_uuid", "realm_uuid").Record(g).ToSQL()
expected := `
INSERT INTO groups ("group_uuid", "realm_uuid")
VALUES ($1, $2)
`
assert.Equal(t, stripWS(expected), stripWS(sql))
assert.Exactly(t, []interface{}{"22", "11"}, args)
}
func TestEmbeddedStructInvalidColumns(t *testing.T) {
type Realm struct {
RealmUUID string
}
type Group struct {
GroupUUID string `db:"group_uuid"`
*Realm
}
g := &Group{Realm: &Realm{"11"}, GroupUUID: "22"}
assert.Panics(t, func() {
// realm_uuid must be explicitly defined
InsertInto("groups").Columns("group_uuid", "realm_uuid").Record(g).ToSQL()
})
}