forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connector_test.go
69 lines (60 loc) · 1.68 KB
/
connector_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
// Copyright (c) 2020-2022 Snowflake Computing Inc. All rights reserved.
package gosnowflake
import (
"context"
"database/sql/driver"
"reflect"
"testing"
)
type noopTestDriver struct {
config Config
conn *snowflakeConn
}
func (d *noopTestDriver) Open(_ string) (driver.Conn, error) {
return nil, nil
}
func (d *noopTestDriver) OpenWithConfig(_ context.Context, config Config) (driver.Conn, error) {
d.config = config
return d.conn, nil
}
func TestConnector(t *testing.T) {
conn := snowflakeConn{}
mock := noopTestDriver{conn: &conn}
createDSN("UTC")
config, err := ParseDSN(dsn)
if err != nil {
t.Fatal("Failed to parse dsn")
}
connector := NewConnector(&mock, *config)
connection, err := connector.Connect(context.Background())
if err != nil {
t.Fatalf("Connect error %s", err)
}
if connection != &conn {
t.Fatalf("Connection mismatch %s", connection)
}
fillMissingConfigParameters(config)
if reflect.DeepEqual(config, mock.config) {
t.Fatalf("Config should be equal, expected %v, actual %v", config, mock.config)
}
if connector.Driver() == nil {
t.Fatalf("Missing driver")
}
}
func TestConnectorWithMissingConfig(t *testing.T) {
conn := snowflakeConn{}
mock := noopTestDriver{conn: &conn}
config := Config{
User: "u",
Password: "p",
Account: "",
}
expectedErr := errEmptyAccount()
connector := NewConnector(&mock, config)
_, err := connector.Connect(context.Background())
assertNotNilF(t, err, "the connection should have failed due to empty account.")
driverErr, ok := err.(*SnowflakeError)
assertTrueF(t, ok, "should be a SnowflakeError")
assertEqualE(t, driverErr.Number, expectedErr.Number)
assertEqualE(t, driverErr.Message, expectedErr.Message)
}