forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection_configuration_test.go
More file actions
65 lines (56 loc) · 2.03 KB
/
connection_configuration_test.go
File metadata and controls
65 lines (56 loc) · 2.03 KB
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
package gosnowflake
import (
"database/sql"
toml "github.com/BurntSushi/toml"
"os"
"strconv"
"testing"
)
// TODO move this test to config package when we have wiremock support in an internal package
func TestTomlConnection(t *testing.T) {
os.Setenv("SNOWFLAKE_HOME", "./test_data/") // TODO replace with snowflakeHome const
os.Setenv("SNOWFLAKE_DEFAULT_CONNECTION_NAME", "toml-connection") // TODO replace with snowflakeConnectionName const
defer os.Unsetenv("SNOWFLAKE_HOME") // TODO replace with snowflakeHome const
defer os.Unsetenv("SNOWFLAKE_DEFAULT_CONNECTION_NAME") // TODO replace with snowflakeHome const
wiremock.registerMappings(t,
wiremockMapping{filePath: "auth/password/successful_flow.json"},
wiremockMapping{filePath: "select1.json", params: map[string]string{
"%AUTHORIZATION_HEADER%": "session token",
}},
)
type Connection struct {
Account string `toml:"account"`
User string `toml:"user"`
Password string `toml:"password"`
Host string `toml:"host"`
Port string `toml:"port"`
Protocol string `toml:"protocol"`
}
type TomlStruct struct {
Connection Connection `toml:"toml-connection"`
}
cfg := wiremock.connectionConfig()
connection := &TomlStruct{
Connection: Connection{
Account: cfg.Account,
User: cfg.User,
Password: cfg.Password,
Host: cfg.Host,
Port: strconv.Itoa(cfg.Port),
Protocol: cfg.Protocol,
},
}
f, err := os.OpenFile("./test_data/connections.toml", os.O_APPEND|os.O_WRONLY, 0600)
assertNilF(t, err, "Failed to create connections.toml file")
defer f.Close()
encoder := toml.NewEncoder(f)
err = encoder.Encode(connection)
assertNilF(t, err, "Failed to parse the config to toml structure")
if !isWindows {
err = os.Chmod("./test_data/connections.toml", 0600)
assertNilF(t, err, "The error occurred because you cannot change the file permission")
}
db, err := sql.Open("snowflake", "autoConfig")
assertNilF(t, err, "The error occurred because the db cannot be established")
runSmokeQuery(t, db)
}