-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_test.go
89 lines (70 loc) · 1.72 KB
/
url_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
package pq
import (
"testing"
)
func TestSimpleParseURL(t *testing.T) {
expected := "host=hostname.remote"
str, err := ParseURL("postgres://hostname.remote")
if err != nil {
t.Error(err)
}
if str != expected {
t.Errorf("unexpected result from ParseURL:\n+ %v\n- %v", str, expected)
}
}
func TestFullParseURL(t *testing.T) {
expected := "dbname=database host=hostname.remote password=secret port=1234 user=username"
str, err := ParseURL("postgres://username:secret@hostname.remote:1234/database")
if err != nil {
t.Error(err)
}
if str != expected {
t.Errorf("unexpected result from ParseURL:\n+ %s\n- %s", str, expected)
}
}
func TestInvalidProtocolParseURL(t *testing.T) {
_, err := ParseURL("http://hostname.remote")
switch err {
case nil:
t.Error("Expected an error from parsing invalid protocol")
default:
msg := "invalid connection protocol: http"
if err.Error() != msg {
t.Errorf("Unexpected error message:\n+ %s\n- %s",
err.Error(), msg)
}
}
}
func TestMinimalURL(t *testing.T) {
cs, err := ParseURL("postgres://")
if err != nil {
t.Error(err)
}
if cs != "" {
t.Errorf("expected blank connection string, got: %q", cs)
}
}
func TestParseMap(t *testing.T) {
m := map[string]interface{}{
"ssl-mode": "disable",
"host": "localhost",
"port": 5432,
}
expected := "host=localhost port=5432 ssl-mode=disable"
paramString, err := ParseMap(m)
if err != nil {
t.Error(err)
}
if paramString != expected {
t.Errorf("expected %s, got %s", expected, paramString)
}
}
func TestAccrue(t *testing.T) {
strings := new(kvs)
strings.accrue("a", "b")
expected := "a=b"
result := strings.String()
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}