-
Notifications
You must be signed in to change notification settings - Fork 1
/
conn_test.go
56 lines (41 loc) · 1.23 KB
/
conn_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
package clickhouse
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConnect(t *testing.T) {
var conn *Conn
tr := getMockTransport("1")
conn = NewConn("host.local", tr)
assert.Equal(t, "http://host.local/", conn.Host)
conn = NewConn("http://host.local/", tr)
assert.Equal(t, "http://host.local/", conn.Host)
conn = NewConn("https://host.local/", tr)
assert.Equal(t, "https://host.local/", conn.Host)
conn = NewConn("http:/host.local", tr)
assert.Equal(t, "http://http:/host.local/", conn.Host)
}
func TestConn_Ping(t *testing.T) {
tr := getMockTransport("1")
conn := NewConn("host.local", tr)
assert.NoError(t, conn.Ping())
}
func TestConn_Ping2(t *testing.T) {
tr := getMockTransport("")
conn := NewConn("host.local", tr)
assert.Error(t, conn.Ping())
}
func TestConn_Ping3(t *testing.T) {
tr := badTransport{err: errors.New("Connection timeout")}
conn := NewConn("host.local", tr)
assert.Error(t, conn.Ping())
assert.Equal(t, "Connection timeout", conn.Ping().Error())
}
func TestAuthConn(t *testing.T) {
tr := authTransport{response: "1"}
conn := NewConn("host.local", tr)
assert.Error(t, conn.Ping())
conn = NewAuthConn("host.local", tr, "user", "pass")
assert.NoError(t, conn.Ping())
}