Skip to content

Commit 666a331

Browse files
committed
use proper test connection
Signed-off-by: Kaviraj <[email protected]>
1 parent 0f3d803 commit 666a331

File tree

4 files changed

+49
-46
lines changed

4 files changed

+49
-46
lines changed

tests/http_exception_test.go

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import (
1010
)
1111

1212
func TestHTTPExceptionHandling(t *testing.T) {
13-
conn, err := clickhouse.Open(&clickhouse.Options{
14-
Protocol: clickhouse.HTTP,
15-
Addr: []string{"localhost:8123"},
16-
})
13+
conn, err := GetNativeConnection(t, clickhouse.HTTP, nil, nil, nil)
1714
require.NoError(t, err)
1815

1916
ctx := context.Background()
@@ -49,43 +46,3 @@ func TestHTTPExceptionHandling(t *testing.T) {
4946

5047
assert.True(t, occured, "execption not caught in the response chunks")
5148
}
52-
53-
func TestHTTPExceptionHandlingDB(t *testing.T) {
54-
conn := clickhouse.OpenDB(&clickhouse.Options{
55-
Protocol: clickhouse.HTTP,
56-
Addr: []string{"localhost:8123"},
57-
})
58-
59-
ctx := context.Background()
60-
61-
// These settings will make sure mid-stream exception most likely on the server
62-
ctx = clickhouse.Context(ctx, clickhouse.WithSettings(clickhouse.Settings{
63-
"max_threads": 1,
64-
"max_block_size": 1,
65-
"http_write_exception_in_output_format": 0,
66-
"wait_end_of_query": 0,
67-
"http_response_buffer_size": 1,
68-
}))
69-
70-
rows, err := conn.QueryContext(ctx, `SELECT throwIf(number=3, 'there is an exception') FROM system.numbers`)
71-
require.NoError(t, err) // query shouldn't fail with 500 status code.
72-
73-
occured := false
74-
// query should fail while scanning the rows mid-stream
75-
for rows.Next() {
76-
var result uint8
77-
err := rows.Scan(&result)
78-
if err != nil {
79-
// should be an exception caught correctly
80-
assert.Contains(t, err.Error(), "there is an exception", "Expected exception message not caught")
81-
occured = true
82-
}
83-
}
84-
85-
if err := rows.Err(); err != nil {
86-
assert.Contains(t, err.Error(), "there is an exception", "Expected exception message not caught")
87-
occured = true
88-
}
89-
90-
assert.True(t, occured, "execption not caught in the response chunks")
91-
}

tests/main_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package tests
32

43
import (

tests/std/http_exception_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package std
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/ClickHouse/clickhouse-go/v2"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestHTTPExceptionHandlingDB(t *testing.T) {
13+
conn, err := GetStdOpenDBConnection(clickhouse.HTTP, nil, nil, nil)
14+
require.NoError(t, err)
15+
16+
ctx := context.Background()
17+
18+
// These settings will make sure mid-stream exception most likely on the server
19+
ctx = clickhouse.Context(ctx, clickhouse.WithSettings(clickhouse.Settings{
20+
"max_threads": 1,
21+
"max_block_size": 1,
22+
"http_write_exception_in_output_format": 0,
23+
"wait_end_of_query": 0,
24+
"http_response_buffer_size": 1,
25+
}))
26+
27+
rows, err := conn.QueryContext(ctx, `SELECT throwIf(number=3, 'there is an exception') FROM system.numbers`)
28+
require.NoError(t, err) // query shouldn't fail with 500 status code.
29+
30+
occured := false
31+
// query should fail while scanning the rows mid-stream
32+
for rows.Next() {
33+
var result uint8
34+
err := rows.Scan(&result)
35+
if err != nil {
36+
// should be an exception caught correctly
37+
assert.Contains(t, err.Error(), "there is an exception", "Expected exception message not caught")
38+
occured = true
39+
}
40+
}
41+
42+
if err := rows.Err(); err != nil {
43+
assert.Contains(t, err.Error(), "there is an exception", "Expected exception message not caught")
44+
occured = true
45+
}
46+
47+
assert.True(t, occured, "execption not caught in the response chunks")
48+
}

tests/std/utils.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package std
32

43
import (

0 commit comments

Comments
 (0)