forked from ClickHouse/clickhouse-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
clickhouse_negative_test.go
39 lines (36 loc) · 1.28 KB
/
clickhouse_negative_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
package clickhouse_test
import (
"database/sql"
"testing"
"github.com/kshvakov/clickhouse"
"github.com/stretchr/testify/assert"
)
func Test_Negative_OpenConnectAndPing(t *testing.T) {
if connect, err := sql.Open("clickhouse", ""); assert.NoError(t, err) {
assert.Error(t, connect.Ping())
}
if connect, err := sql.Open("clickhouse", "tcp://127.0.0.1:10000"); assert.NoError(t, err) {
assert.Error(t, connect.Ping())
}
if connect, err := sql.Open("clickhouse", "tcp://127.0.0.1:9000?username=invalid"); assert.NoError(t, err) {
if err := connect.Ping(); assert.Error(t, err) {
if exception, ok := err.(*clickhouse.Exception); assert.True(t, ok) {
assert.Equal(t, int32(192), exception.Code)
}
}
}
if connect, err := sql.Open("clickhouse", "tcp://127.0.0.1:9000?password=invalid"); assert.NoError(t, err) {
if err := connect.Ping(); assert.Error(t, err) {
if exception, ok := err.(*clickhouse.Exception); assert.True(t, ok) {
assert.Equal(t, int32(193), exception.Code)
}
}
}
if connect, err := sql.Open("clickhouse", "tcp://127.0.0.1:9000?database=invalid"); assert.NoError(t, err) {
if err := connect.Ping(); assert.Error(t, err) {
if exception, ok := err.(*clickhouse.Exception); assert.True(t, ok) {
assert.Equal(t, int32(81), exception.Code)
}
}
}
}