-
Notifications
You must be signed in to change notification settings - Fork 90
/
conn_go18_test.go
69 lines (60 loc) · 2.28 KB
/
conn_go18_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//go:build go1.8
// +build go1.8
package clickhouse
import (
"context"
"database/sql/driver"
"time"
)
var (
_ driver.ExecerContext = new(conn)
_ driver.QueryerContext = new(conn)
_ driver.ConnPrepareContext = new(conn)
_ driver.ConnBeginTx = new(conn)
_ driver.Pinger = new(conn)
)
func (s *connSuite) TestQueryContext() {
ctx, cancel := context.WithCancel(context.Background())
time.AfterFunc(5*time.Millisecond, cancel)
_, err := s.conn.QueryContext(ctx, "SELECT sleep(3)")
s.EqualError(err, "doRequest: transport failed to send a request to ClickHouse: context canceled")
}
func (s *connSuite) TestExecContext() {
ctx, cancel := context.WithCancel(context.Background())
time.AfterFunc(5*time.Millisecond, cancel)
_, err := s.conn.ExecContext(ctx, "SELECT sleep(3)")
s.EqualError(err, "doRequest: transport failed to send a request to ClickHouse: context canceled")
}
func (s *connSuite) TestPing() {
s.NoError(s.conn.Ping())
ctx, cancel := context.WithCancel(context.Background())
cancel()
s.EqualError(s.conn.PingContext(ctx), "context canceled")
}
func (s *connSuite) TestPassRequestQueryParamsFromContext() {
ctx := context.WithValue(context.Background(), RequestQueryParams, map[string]string{
"max_read_buffer_size": "1",
})
s.NoError(s.conn.PingContext(ctx))
ctx = context.WithValue(context.Background(), RequestQueryParams, map[string]string{
"no_cache": "1",
})
s.EqualError(s.conn.PingContext(ctx), "Code: 115, Message: Setting no_cache is neither a builtin setting nor started with the prefix 'SQL_' registered for user-defined settings")
}
func (s *connSuite) TestColumnTypes() {
rows, err := s.conn.Query("SELECT * FROM data LIMIT 1")
s.Require().NoError(err)
defer rows.Close()
types, err := rows.ColumnTypes()
s.Require().NoError(err)
expected := []string{
"Int64", "UInt64", "Float64", "Bool", "String", "String", "Array(Int16)", "Array(UInt8)", "Date", "DateTime",
"Enum8('one' = 1, 'two' = 2, 'three' = 3)",
"Decimal(9, 4)", "Decimal(18, 4)", "Decimal(38, 4)", "Decimal(10, 4)", "IPv4", "IPv6", "FixedString(8)", "LowCardinality(String)",
"Map(String, Array(Int64))", "Map(String, Int64)", "Map(Int32, Int32)",
}
s.Require().Equal(len(expected), len(types))
for i, e := range expected {
s.Equal(e, types[i].DatabaseTypeName())
}
}