-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_update_test.go
More file actions
80 lines (72 loc) · 2.77 KB
/
sql_update_test.go
File metadata and controls
80 lines (72 loc) · 2.77 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package StitchingSQLGo
import (
"github.com/google/go-cmp/cmp"
"testing"
)
//go:generate stitching_sql -type=TestUpdate_SQLTable -file-name=sql_update_table_stitching_sql_test.go -is-add-import=false
type TestUpdate_SQLTable struct {
Field1 int
Field2 int
Field3 int
}
func TestUpdate_SQL(t *testing.T) {
u := Update{
Table: TestUpdate_SQLTable{},
Set: map[Field]interface{}{
TestUpdate_SQLTable_F.Field1: 1,
TestUpdate_SQLTable_F.Field2: 2,
TestUpdate_SQLTable_F.Field3: 3,
},
Where: Where{
Condition{
L: TestUpdate_SQLTable_F.Field1,
O: EQ,
R: 4,
},
AND,
WhereItems{
Condition{
L: TestUpdate_SQLTable_F.Field1,
O: EQ,
R: 5,
},
AND,
Condition{
L: TestUpdate_SQLTable_F.Field2,
O: EQ,
R: 6,
},
AND,
Condition{
L: TestUpdate_SQLTable_F.Field3,
O: EQ,
R: 7,
},
},
},
Returning: Returning{
TestUpdate_SQLTable_F.Field1,
TestUpdate_SQLTable_F.Field2,
TestUpdate_SQLTable_F.Field3,
},
}
sql, args, err := u.SQL()
if err != nil {
t.Fatal(err)
}
a := map[string][]interface{}{
"update test_update__sqltable set field1 = $1, field2 = $2, field3 = $3 where test_update__sqltable.field1 = $4 and ( test_update__sqltable.field1 = $5 and test_update__sqltable.field2 = $6 and test_update__sqltable.field3 = $7)": {1, 2, 3, 4, 5, 6, 7},
"update test_update__sqltable set field2 = $1, field1 = $2, field3 = $3 where test_update__sqltable.field1 = $4 and ( test_update__sqltable.field1 = $5 and test_update__sqltable.field2 = $6 and test_update__sqltable.field3 = $7)": {2, 1, 3, 4, 5, 6, 7},
"update test_update__sqltable set field3 = $1, field2 = $2, field1 = $3 where test_update__sqltable.field1 = $4 and ( test_update__sqltable.field1 = $5 and test_update__sqltable.field2 = $6 and test_update__sqltable.field3 = $7)": {3, 2, 1, 4, 5, 6, 7},
"update test_update__sqltable set field2 = $1, field3 = $2, field1 = $3 where test_update__sqltable.field1 = $4 and ( test_update__sqltable.field1 = $5 and test_update__sqltable.field2 = $6 and test_update__sqltable.field3 = $7)": {2, 3, 1, 4, 5, 6, 7},
"update test_update__sqltable set field3 = $1, field1 = $2, field2 = $3 where test_update__sqltable.field1 = $4 and ( test_update__sqltable.field1 = $5 and test_update__sqltable.field2 = $6 and test_update__sqltable.field3 = $7)": {3, 1, 2, 4, 5, 6, 7},
"update test_update__sqltable set field1 = $1, field3 = $2, field2 = $3 where test_update__sqltable.field1 = $4 and ( test_update__sqltable.field1 = $5 and test_update__sqltable.field2 = $6 and test_update__sqltable.field3 = $7)": {1, 3, 2, 4, 5, 6, 7},
}
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)
}
}