-
Notifications
You must be signed in to change notification settings - Fork 11
/
block_test.go
89 lines (83 loc) · 2.32 KB
/
block_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package chconn
import (
"context"
"errors"
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBlockReadError(t *testing.T) {
startValidReader := 15
tests := []struct {
name string
wantErr string
numberValid int
}{
{
name: "blockInfo: temporary table",
wantErr: "block: temporary table",
numberValid: startValidReader - 1,
}, {
name: "blockInfo: read field1",
wantErr: "blockInfo: read field1",
numberValid: startValidReader,
}, {
name: "blockInfo: read isOverflows",
wantErr: "blockInfo: read isOverflows",
numberValid: startValidReader + 1,
}, {
name: "blockInfo: read field2",
wantErr: "blockInfo: read field2",
numberValid: startValidReader + 2,
}, {
name: "blockInfo: read bucketNum",
wantErr: "blockInfo: read bucketNum",
numberValid: startValidReader + 3,
}, {
name: "blockInfo: read num3",
wantErr: "blockInfo: read num3",
numberValid: startValidReader + 4,
}, {
name: "block: read NumColumns",
wantErr: "block: read NumColumns",
numberValid: startValidReader + 5,
}, {
name: "block: read NumRows",
wantErr: "block: read NumRows",
numberValid: startValidReader + 6,
}, {
name: "block: read column name",
wantErr: "block: read column name",
numberValid: startValidReader + 8,
}, {
name: "block: read column type",
wantErr: "block: read column type",
numberValid: startValidReader + 10,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config, err := ParseConfig(os.Getenv("CHX_TEST_TCP_CONN_STRING"))
require.NoError(t, err)
config.ReaderFunc = func(r io.Reader) io.Reader {
return &readErrorHelper{
err: errors.New("timeout"),
r: r,
numberValid: tt.numberValid,
}
}
c, err := ConnectConfig(context.Background(), config)
assert.NoError(t, err)
stmt, err := c.Select(context.Background(), "SELECT * FROM system.numbers LIMIT 5;")
require.Error(t, err)
require.Nil(t, stmt)
readErr, ok := err.(*readError)
require.True(t, ok)
require.Equal(t, readErr.msg, tt.wantErr)
require.EqualError(t, readErr.Unwrap(), "timeout")
assert.True(t, c.IsClosed())
})
}
}