forked from fajran/go-monetdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver_test.go
58 lines (50 loc) · 1.54 KB
/
driver_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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package monetdb
import (
"strconv"
"testing"
)
func TestParseDSN(t *testing.T) {
tcs := [][]string{
[]string{"me:secret@localhost:1234/testdb", "me", "secret", "localhost", "1234", "testdb"},
[]string{"me@localhost:1234/testdb", "me", "", "localhost", "1234", "testdb"},
[]string{"localhost:1234/testdb", "", "", "localhost", "1234", "testdb"},
[]string{"localhost/testdb", "", "", "localhost", "50000", "testdb"},
[]string{"localhost"},
[]string{"/testdb"},
[]string{"/"},
[]string{""},
[]string{":secret@localhost:1234/testdb"},
}
for _, tc := range tcs {
n := tc[0]
ok := len(tc) > 1
c, err := parseDSN(n)
if ok && err != nil {
t.Errorf("Error parsing DSN: %s -> %v", n, err)
} else if !ok && err == nil {
t.Errorf("Error parsing invalid DSN: %s", n)
}
if !ok || err != nil {
continue
}
port, _ := strconv.Atoi(tc[4])
if c.Username != tc[1] {
t.Errorf("Invalid username: %s, expected: %s", c.Username, tc[1])
}
if c.Password != tc[2] {
t.Errorf("Invalid password: %s, expected: %s", c.Password, tc[2])
}
if c.Hostname != tc[3] {
t.Errorf("Invalid hostname: %s, expected: %s", c.Hostname, tc[3])
}
if c.Port != port {
t.Errorf("Invalid port: %s, expected: %s", c.Port, port)
}
if c.Database != tc[5] {
t.Errorf("Invalid database: %s, expected: %s", c.Database, tc[5])
}
}
}