forked from mailru/go-clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rows_test.go
55 lines (48 loc) · 1.38 KB
/
rows_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
package clickhouse
import (
"bytes"
"database/sql/driver"
"io"
"io/ioutil"
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type bufReadCloser struct {
*bytes.Reader
}
func (r *bufReadCloser) Close() error {
return nil
}
func TestTextRows(t *testing.T) {
buf := bytes.NewReader([]byte("Number\tText\nInt32\tString\n1\t'hello'\n2\t'world'\n"))
rows, err := newTextRows(&conn{}, &bufReadCloser{buf}, time.Local, false)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, []string{"Number", "Text"}, rows.Columns())
assert.Equal(t, []string{"Int32", "String"}, rows.types)
assert.Equal(t, reflect.TypeOf(int32(0)), rows.ColumnTypeScanType(0))
assert.Equal(t, reflect.TypeOf(""), rows.ColumnTypeScanType(1))
assert.Equal(t, "Int32", rows.ColumnTypeDatabaseTypeName(0))
assert.Equal(t, "String", rows.ColumnTypeDatabaseTypeName(1))
assert.Equal(t, time.Local, rows.decode.(*textDecoder).location)
dest := make([]driver.Value, 2)
if !assert.NoError(t, rows.Next(dest)) {
return
}
assert.Equal(t, []driver.Value{int32(1), "hello"}, dest)
if !assert.NoError(t, rows.Next(dest)) {
return
}
assert.Equal(t, []driver.Value{int32(2), "world"}, dest)
data, err := ioutil.ReadAll(rows.respBody)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, 0, len(data))
assert.Equal(t, io.EOF, rows.Next(dest))
assert.NoError(t, rows.Close())
assert.Empty(t, data)
}