-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect_test.go
More file actions
76 lines (67 loc) · 1.45 KB
/
connect_test.go
File metadata and controls
76 lines (67 loc) · 1.45 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
66
67
68
69
70
71
72
73
74
75
76
package dotpgx
import (
"reflect"
"strings"
"testing"
"github.com/jackc/pgx"
)
var testConfig = Config{
"name",
"host",
321,
false,
"user",
"password",
123,
dbRuntime{},
}
func TestConnPoolConfig(t *testing.T) {
c := testConfig
exp := pgx.ConnPoolConfig{
MaxConnections: c.MaxConnections,
ConnConfig: pgx.ConnConfig{
Database: c.Name,
Host: c.Host,
Port: uint16(c.Port),
User: c.User,
Password: c.Password,
RuntimeParams: nil,
},
}
got := c.ConnPoolConfig()
if !reflect.DeepEqual(got, exp) {
t.Error("\nExpected:\n", exp, "\nGot:\n", got)
}
c.TLS = true
got = c.ConnPoolConfig()
if got.TLSConfig == nil {
t.Fatal("TLSConfig nil")
}
if got.TLSConfig.ServerName != c.Host {
t.Error("Expected:", c.Host, "Got:", got.TLSConfig.ServerName)
}
c.RunTime.AppName = "appname"
got = c.ConnPoolConfig()
a, ok := got.RuntimeParams["application_name"]
if !ok {
t.Fatal("Application name not set")
}
if a != c.RunTime.AppName {
t.Error("Expected:", c.RunTime.AppName, "Got:", a)
}
}
func TestInitDB(t *testing.T) {
exp := "no such host"
_, err := InitDB(testConfig, "")
if err == nil || !strings.HasSuffix(err.Error(), exp) {
t.Error("Expected error", exp, "Got:", err)
}
exp = "No files to parse"
_, err = InitDB(Default, "_")
if err == nil || err.Error() != exp {
t.Error("Expected error", exp, "Got:", err)
}
if _, err = InitDB(Default, ""); err != nil {
t.Error(err)
}
}