-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_insert_test.go
More file actions
53 lines (45 loc) · 2.04 KB
/
sql_insert_test.go
File metadata and controls
53 lines (45 loc) · 2.04 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
package StitchingSQLGo
import (
"github.com/google/go-cmp/cmp"
"testing"
)
//go:generate stitching_sql -type=TestInsert_SQLTable -file-name=sql_insert_table_stitching_sql_test.go -is-add-import=false
type TestInsert_SQLTable struct {
Field1 int
Field2 int
Field3 int
}
func TestInsert_SQL(t *testing.T) {
i := Insert{
Table: TestInsert_SQLTable{},
Values: map[Field]interface{}{
TestInsert_SQLTable_F.Field1: 1,
TestInsert_SQLTable_F.Field2: 2,
TestInsert_SQLTable_F.Field3: 3,
},
Returning: Returning{
TestInsert_SQLTable_F.Field1,
TestInsert_SQLTable_F.Field2,
TestInsert_SQLTable_F.Field3,
},
}
sql, args, err := i.SQL()
if err != nil {
t.Fatal(err)
}
a := map[string][]interface{}{
"insert into test_insert__sqltable ( field1, field2, field3) values ( $1, $2, $3) returning test_insert__sqltable.field1, test_insert__sqltable.field2, test_insert__sqltable.field3": {1, 2, 3},
"insert into test_insert__sqltable ( field2, field1, field3) values ( $1, $2, $3) returning test_insert__sqltable.field1, test_insert__sqltable.field2, test_insert__sqltable.field3": {2, 1, 3},
"insert into test_insert__sqltable ( field3, field2, field1) values ( $1, $2, $3) returning test_insert__sqltable.field1, test_insert__sqltable.field2, test_insert__sqltable.field3": {3, 2, 1},
"insert into test_insert__sqltable ( field2, field3, field1) values ( $1, $2, $3) returning test_insert__sqltable.field1, test_insert__sqltable.field2, test_insert__sqltable.field3": {2, 3, 1},
"insert into test_insert__sqltable ( field3, field1, field2) values ( $1, $2, $3) returning test_insert__sqltable.field1, test_insert__sqltable.field2, test_insert__sqltable.field3": {3, 1, 2},
"insert into test_insert__sqltable ( field1, field3, field2) values ( $1, $2, $3) returning test_insert__sqltable.field1, test_insert__sqltable.field2, test_insert__sqltable.field3": {1, 3, 2},
}
exceptArgs, ok := a[sql]
if ok == false {
t.Fatalf("now\n%s", sql)
}
if cmp.Equal(exceptArgs, args) == false {
t.Fatalf("except\n%v\nnow\n%v", exceptArgs, args)
}
}