-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn_test.go
73 lines (61 loc) · 1.61 KB
/
conn_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
package pgc
import (
"flag"
"os"
"strings"
"testing"
"github.com/davecgh/go-spew/spew"
)
/*
Configure the running of the main to create and config a temp/test db
*/
func TestMain(m *testing.M) {
flag.Parse()
envDBName := os.Getenv("POSTGRES_DB")
var shouldDropDB bool
if !strings.HasPrefix(envDBName, "pgc_tmp") {
// Create and new a tmp db
envDBName = CreateDB("pgc_tmp")
shouldDropDB = true
}
// Will default to the current os username, no pass, no tls
MustInit(envDBName, "localhost", "", "", false, 0)
// Set up spew to not use string reps (helpful for buggin')
spew.Config.DisableMethods = true
exitVal := m.Run()
ClosePool()
if shouldDropDB {
DropDB(envDBName)
}
os.Exit(exitVal)
}
// Just to get some coverage on our init process beyond TestMain above
func TestInitFromEnvBadPort(t *testing.T) {
myConfig := GetConfig()
badPort := "2lk3j4lk234j"
os.Setenv(myConfig.EnvVarNamePort, badPort)
func() { // Call an inline function to test and deal with the panic
defer func() {
if r := recover(); r == nil {
t.Errorf("TestInitFromEnvBadPort should have panicked on bad port (%s)",
badPort)
}
}()
InitFromEnv()
}()
}
func TestInitMissingDBName(t *testing.T) {
func() { // Call an inline function to test and deal with the panic
defer func() {
if r := recover(); r == nil {
t.Error("TestInitMissingDBName should have panicked on missing db name")
}
}()
MustInit("", "localhost", "", "", false, 0)
}()
}
// Not going to bother with a negative test here since it will
// require a way to destory the connection pool, ug
func TestMustPing(t *testing.T) {
MustPing()
}