-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdsn_test.go
107 lines (80 loc) · 4.95 KB
/
dsn_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package fireboltgosdk
import (
"testing"
"github.com/firebolt-db/firebolt-go-sdk/types"
)
const mockUserName = "[email protected]"
func runDSNTest(t *testing.T, input string, expectedSettings types.FireboltSettings) {
settings, err := ParseDSNString(input)
if err != nil {
t.Errorf("ParseDSNString unexpectedly failed: %v", err)
}
if settings.AccountName != expectedSettings.AccountName {
t.Errorf("for account_name got %s want %s", settings.AccountName, expectedSettings.AccountName)
}
if settings.EngineName != expectedSettings.EngineName {
t.Errorf("for engine got %s want %s", settings.EngineName, expectedSettings.EngineName)
}
if settings.ClientID != expectedSettings.ClientID {
t.Errorf("for client_id got %s want %s", settings.ClientID, expectedSettings.ClientID)
}
if settings.ClientSecret != expectedSettings.ClientSecret {
t.Errorf("for client_secret got %s want %s", settings.ClientSecret, expectedSettings.ClientSecret)
}
if settings.Database != expectedSettings.Database {
t.Errorf("for Database got %s want %s", settings.Database, expectedSettings.Database)
}
if settings.NewVersion != expectedSettings.NewVersion {
t.Errorf("for NewVersion got %t want %t", settings.NewVersion, expectedSettings.NewVersion)
}
}
func runDSNTestFail(t *testing.T, input string) {
_, err := ParseDSNString(input)
if err == nil {
t.Errorf("expected to fail with %s, but didn't", input)
}
}
func TestDSNHappyPath(t *testing.T) {
runDSNTest(t, "firebolt://", types.FireboltSettings{NewVersion: true})
runDSNTest(t, "firebolt:///test_db", types.FireboltSettings{Database: "test_db", NewVersion: true})
runDSNTest(t, "firebolt://?account_name=test_acc&engine=test_eng&client_id=test_cid&client_secret=test_cs",
types.FireboltSettings{AccountName: "test_acc", EngineName: "test_eng", ClientID: "test_cid", ClientSecret: "test_cs", NewVersion: true})
runDSNTest(t, "firebolt:///test_db?account_name=test_acc&engine=test_eng&client_id=test_cid&client_secret=test_cs",
types.FireboltSettings{Database: "test_db", AccountName: "test_acc", EngineName: "test_eng", ClientID: "test_cid", ClientSecret: "test_cs", NewVersion: true})
// special characters
runDSNTest(t, "firebolt:///test_db?account_name=test_acc&engine=test_eng&client_id=test_cid&client_secret=test_*-()@\\.",
types.FireboltSettings{Database: "test_db", AccountName: "test_acc", EngineName: "test_eng", ClientID: "test_cid", ClientSecret: "test_*-()@\\.", NewVersion: true})
}
// TestDSNFailed test different failure scenarios for ParseDSNString
func TestDSNFailed(t *testing.T) {
runDSNTestFail(t, "")
runDSNTestFail(t, "other_db://")
runDSNTestFail(t, "firebolt://db") // another / is needed before a db
runDSNTestFail(t, "firebolt://?k=v") // unknown parameter name
runDSNTestFail(t, "firebolt:///db?k=v") // unknown parameter name
}
func TestDSNV0HappyPath(t *testing.T) {
runDSNTest(t, "firebolt://[email protected]:password@db_name",
types.FireboltSettings{ClientID: mockUserName, ClientSecret: "password", Database: "db_name", NewVersion: false})
runDSNTest(t, "firebolt://[email protected]:password@db_name/engine_name",
types.FireboltSettings{ClientID: mockUserName, ClientSecret: "password", Database: "db_name", EngineName: "engine_name", NewVersion: false})
runDSNTest(t, "firebolt://[email protected]:password@db_name/engine_name",
types.FireboltSettings{ClientID: mockUserName, ClientSecret: "password", Database: "db_name", EngineName: "engine_name", NewVersion: false})
runDSNTest(t, "firebolt://[email protected]:password@db_name/engine_url.firebolt.io",
types.FireboltSettings{ClientID: mockUserName, ClientSecret: "password", Database: "db_name", EngineName: "engine_url.firebolt.io", NewVersion: false})
runDSNTest(t, "firebolt://[email protected]:password@db_name/https://engine_url.firebolt.io",
types.FireboltSettings{ClientID: mockUserName, ClientSecret: "password", Database: "db_name", EngineName: "https://engine_url.firebolt.io", NewVersion: false})
runDSNTest(t, "firebolt://[email protected]:password@db_name?account_name=firebolt_account",
types.FireboltSettings{ClientID: mockUserName, ClientSecret: "password", Database: "db_name", AccountName: "firebolt_account", NewVersion: false})
runDSNTest(t, "firebolt://user@fire:bolt.io:passwo@rd@db_name?account_name=firebolt_account",
types.FireboltSettings{ClientID: "user@fire:bolt.io", ClientSecret: "passwo@rd", Database: "db_name", AccountName: "firebolt_account", NewVersion: false})
runDSNTest(t, "firebolt://client_id:client_secret@db_name?account_name=firebolt_account",
types.FireboltSettings{ClientID: "client_id", ClientSecret: "client_secret", Database: "db_name", AccountName: "firebolt_account", NewVersion: true})
}
// TestDSNFailed test different failure scenarios for ParseDSNString
func TestDSNV0Failed(t *testing.T) {
runDSNTestFail(t, "")
runDSNTestFail(t, "firebolt://user:yury_db")
runDSNTestFail(t, "jdbc://user:yury_db@db_name")
runDSNTestFail(t, "firebolt://yury_db@dn_name?account_name=firebolt_account")
}