This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_test.go
144 lines (132 loc) · 3.37 KB
/
main_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"runtime"
"testing"
)
func Test_isIn(t *testing.T) {
httpGood := []int{200, 201, 202, 203, 204, 205, 206, 207, 208, 226}
if !isIn(httpGood, 200) {
t.Errorf("Expected 200 to be in httpGood")
}
if isIn(httpGood, 20) {
t.Errorf("Expected 20 to not be in httpGood")
}
}
func Test_isInPath(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
if err := isInPath("date"); err != nil {
t.Errorf("Expected date to be in path.")
}
}
if err := isInPath("dateabcdefgh"); err == nil {
t.Errorf("Expected random cmd to not be in path.")
}
}
func Test_splitPostgresURL(t *testing.T) {
var h, p, u, hExp, pExp, uExp string
var err error
h, p, u, err = splitPostgresURL("postgres://127.0.0.1:230")
if err != nil {
t.Errorf("Expected error to be nil. Got %v.\n", err)
}
hExp = "127.0.0.1"
if h != hExp {
t.Errorf("Expected host to be %s. Got %s.\n", hExp, h)
}
pExp = "230"
if p != pExp {
t.Errorf("Expected port to be %s. Got %s.\n", pExp, p)
}
uExp = ""
if u != uExp {
t.Errorf("Expected port to be %s. Got %s.\n", uExp, u)
}
h, p, u, err = splitPostgresURL("postgres://127.0.0.1:230/")
if err != nil {
t.Errorf("Expected error to be %v. Got %v.\n", nil, err)
}
hExp = "127.0.0.1"
if h != hExp {
t.Errorf("Expected host to be %s. Got %s.\n", hExp, h)
}
pExp = "230"
if p != pExp {
t.Errorf("Expected port to be %s. Got %s.\n", pExp, p)
}
uExp = ""
if u != uExp {
t.Errorf("Expected port to be %s. Got %s.\n", uExp, u)
}
h, p, u, err = splitPostgresURL("postgres://localhost/")
if err != nil {
t.Errorf("Expected error to be %v. Got %v.\n", nil, err)
}
hExp = "localhost"
if h != hExp {
t.Errorf("Expected host to be %s. Got %s.\n", hExp, h)
}
pExp = ""
if p != pExp {
t.Errorf("Expected port to be %s. Got %s.\n", pExp, p)
}
uExp = ""
if u != uExp {
t.Errorf("Expected port to be %s. Got %s.\n", uExp, u)
}
h, p, u, err = splitPostgresURL("1postgres://localhost/")
if err == nil {
t.Errorf("Expected error to be non nil. Got %v.\n", err)
}
}
func Test_splitPostgresURL_withUser(t *testing.T) {
var h, p, u, hExp, pExp, uExp string
var err error
h, p, u, err = splitPostgresURL("postgres://[email protected]:230")
if err != nil {
t.Errorf("Expected error to be nil. Got %v.\n", err)
}
hExp = "127.0.0.1"
if h != hExp {
t.Errorf("Expected host to be %s. Got %s.\n", hExp, h)
}
pExp = "230"
if p != pExp {
t.Errorf("Expected port to be %s. Got %s.\n", pExp, p)
}
uExp = "user1"
if u != uExp {
t.Errorf("Expected port to be %s. Got %s.\n", uExp, u)
}
h, p, u, err = splitPostgresURL("postgres://@127.0.0.1:230")
if err != nil {
t.Errorf("Expected error to be nil. Got %v.\n", err)
}
hExp = "127.0.0.1"
if h != hExp {
t.Errorf("Expected host to be %s. Got %s.\n", hExp, h)
}
pExp = "230"
if p != pExp {
t.Errorf("Expected port to be %s. Got %s.\n", pExp, p)
}
uExp = ""
if u != uExp {
t.Errorf("Expected port to be %s. Got %s.\n", uExp, u)
}
h, p, u, err = splitPostgresURL("postgres://[email protected]:230")
if err != nil {
t.Errorf("Expected error to be nil. Got %v.\n", err)
}
hExp = "127.0.0.1"
if h != hExp {
t.Errorf("Expected host to be %s. Got %s.\n", hExp, h)
}
pExp = "230"
if p != pExp {
t.Errorf("Expected port to be %s. Got %s.\n", pExp, p)
}
uExp = "abcd.efgh.ijkl"
if u != uExp {
t.Errorf("Expected port to be %s. Got %s.\n", uExp, u)
}
}