-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_test.go
50 lines (44 loc) · 1.37 KB
/
update_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
45
46
47
48
49
50
package sqlparser_test
import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/viant/sqlparser"
"testing"
)
func TestParseUpdate(t *testing.T) {
var testCases = []struct {
description string
SQL string
expect string
}{
{
description: "bq table select",
SQL: "UPDATE users SET name = 'Smith', last_access_time = ? WHERE id = 2",
expect: "UPDATE users SET name = 'Smith', last_access_time = ? WHERE id = 2",
},
{
description: "incremental update",
SQL: "UPDATE users SET name = 'Smith', value=value+?, last_access_time = ? WHERE id = 2",
expect: "UPDATE users SET name = 'Smith', value = value + ?, last_access_time = ? WHERE id = 2",
},
{
description: "incremental update",
SQL: "UPDATE table1[id=?].tt SET name = 'Smith', value= ?, last_access_time = ? WHERE id = 2",
expect: "UPDATE table1[id=?].tt SET name = 'Smith', value = ?, last_access_time = ? WHERE id = 2",
},
}
//for _, testCase := range testCases[len(testCases)-1:] {
for _, testCase := range testCases {
update, err := sqlparser.ParseUpdate(testCase.SQL)
if !assert.Nil(t, err) {
fmt.Printf("%v\n", testCase.SQL)
continue
}
actual := sqlparser.Stringify(update)
if !assert.EqualValues(t, testCase.expect, actual) {
data, _ := json.Marshal(update)
fmt.Printf("%s\n", data)
}
}
}