-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_test.go
96 lines (92 loc) · 2.29 KB
/
config_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
// Copyright 2014 Daniel Theophanes.
// Use of this source code is governed by a zlib-style
// license that can be found in the LICENSE file.
package rdb
import (
"bytes"
"encoding/json"
"testing"
)
var configTestPass = map[string]*Config{
"driver://username:password@localUrl:1234/ServerInstance?db=mydatabase&opt_1=valA&opt_2=valB": {
DriverName: "driver",
Username: "username",
Password: "password",
Hostname: "localUrl",
Port: 1234,
Instance: "ServerInstance",
Database: "mydatabase",
KV: map[string]interface{}{
"1": "valA",
"2": "valB",
},
},
"driver://username:password@localUrl:1234?db=mydatabase": {
DriverName: "driver",
Username: "username",
Password: "password",
Hostname: "localUrl",
Port: 1234,
Instance: "",
Database: "mydatabase",
KV: make(map[string]interface{}),
},
"driver://username@localUrl?db=mydatabase": {
DriverName: "driver",
Username: "username",
Password: "",
Hostname: "localUrl",
Port: 0,
Instance: "",
Database: "mydatabase",
KV: make(map[string]interface{}),
},
"driver://localUrl?db=mydatabase": {
DriverName: "driver",
Username: "",
Password: "",
Hostname: "localUrl",
Port: 0,
Instance: "",
Database: "mydatabase",
KV: make(map[string]interface{}),
},
"sqlite:///C:/folder/file.sqlite3?opt_1=valA&opt_2=valB": {
DriverName: "sqlite",
Username: "",
Password: "",
Hostname: "",
Port: 0,
Instance: "C:/folder/file.sqlite3",
Database: "",
KV: map[string]interface{}{
"1": "valA",
"2": "valB",
},
},
"sqlite:///srv/folder/file.sqlite3": {
DriverName: "sqlite",
Username: "",
Password: "",
Hostname: "",
Port: 0,
Instance: "srv/folder/file.sqlite3",
Database: "",
KV: make(map[string]interface{}),
},
}
func TestConfigURL(t *testing.T) {
for url, confExpect := range configTestPass {
conf, err := ParseConfigURL(url)
if err != nil {
if _, is := err.(DriverNotFound); !is {
t.Fatalf("Invalid connection string: %v", err)
}
}
got, _ := json.MarshalIndent(conf, "", "\t")
want, _ := json.MarshalIndent(confExpect, "", "\t")
if !bytes.Equal(got, want) {
t.Errorf("Not as expected:\nurl: %s\ngot: %s\nwant: %s", url, got, want)
}
}
}