-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_columns_test.go
More file actions
57 lines (51 loc) · 1.41 KB
/
insert_columns_test.go
File metadata and controls
57 lines (51 loc) · 1.41 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
package squildx
import (
"errors"
"reflect"
"testing"
)
func TestInsertColumns(t *testing.T) {
q := NewInsert().Columns("name", "email")
ib := q.(*insertBuilder)
want := []string{"name", "email"}
if !reflect.DeepEqual(ib.columns, want) {
t.Errorf("columns = %v, want %v", ib.columns, want)
}
}
func TestInsertColumns_Chained(t *testing.T) {
q := NewInsert().Columns("name").Columns("email")
ib := q.(*insertBuilder)
want := []string{"name", "email"}
if !reflect.DeepEqual(ib.columns, want) {
t.Errorf("columns = %v, want %v", ib.columns, want)
}
}
func TestInsertColumns_Immutability(t *testing.T) {
base := NewInsert().Columns("name")
_ = base.Columns("email")
ib := base.(*insertBuilder)
want := []string{"name"}
if !reflect.DeepEqual(ib.columns, want) {
t.Errorf("base columns = %v, want %v", ib.columns, want)
}
}
func TestInsertColumnsObject(t *testing.T) {
type User struct {
Name string `db:"name"`
Email string `db:"email"`
}
q := NewInsert().ColumnsObject(User{})
ib := q.(*insertBuilder)
want := []string{"name", "email"}
if !reflect.DeepEqual(ib.columns, want) {
t.Errorf("columns = %v, want %v", ib.columns, want)
}
}
func TestInsertColumnsObject_NotAStruct(t *testing.T) {
q := NewInsert().Into("users").ColumnsObject("not a struct").
Values(":x", Params{"x": 1})
_, _, err := q.Build()
if !errors.Is(err, ErrNotAStruct) {
t.Errorf("expected ErrNotAStruct, got: %v", err)
}
}