forked from ent/ent
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathydb_test.go
More file actions
92 lines (82 loc) · 1.98 KB
/
ydb_test.go
File metadata and controls
92 lines (82 loc) · 1.98 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
81
82
83
84
85
86
87
88
89
90
91
92
package sql
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestYDB_Placeholder(t *testing.T) {
d := YDB{}
assert.Equal(t, "$", d.Placeholder())
}
func TestYDB_Array(t *testing.T) {
d := YDB{}
assert.Equal(t, "?", d.Array())
}
func TestYDB_Drivers(t *testing.T) {
d := YDB{}
drivers := d.Drivers()
assert.Equal(t, []string{"ydb"}, drivers)
}
func TestYDB_Schema(t *testing.T) {
d := YDB{}
assert.Equal(t, "ydb", d.Schema())
}
func TestYDB_ConvertType(t *testing.T) {
d := YDB{}
tests := []struct {
name string
input interface{}
expected YDBType
wantErr bool
}{
{"int8", int8(1), YDBTypeInt8, false},
{"int16", int16(1), YDBTypeInt16, false},
{"int32", int32(1), YDBTypeInt32, false},
{"int64", int64(1), YDBTypeInt64, false},
{"uint8", uint8(1), YDBTypeUint8, false},
{"uint16", uint16(1), YDBTypeUint16, false},
{"uint32", uint32(1), YDBTypeUint32, false},
{"uint64", uint64(1), YDBTypeUint64, false},
{"float32", float32(1), YDBTypeFloat, false},
{"float64", float64(1), YDBTypeDouble, false},
{"string", "test", YDBTypeString, false},
{"[]byte", []byte("test"), YDBTypeBytes, false},
{"bool", true, YDBTypeBool, false},
{"unsupported", struct{}{}, "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := d.ConvertType(tt.input)
if tt.wantErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.expected, got)
})
}
}
func TestYDBDriver_ModifyQuery(t *testing.T) {
d := &YDBDriver{}
tests := []struct {
name string
input string
expected string
}{
{
name: "replace LIMIT",
input: "SELECT * FROM users LIMIT 10",
expected: "SELECT * FROM users TOP 10",
},
{
name: "no modification needed",
input: "SELECT * FROM users",
expected: "SELECT * FROM users",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := d.modifyQuery(tt.input)
assert.Equal(t, tt.expected, got)
})
}
}