This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
main_test.go
162 lines (139 loc) · 4.06 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"net/http"
"os"
"testing"
"github.com/heroku/hk/postgresql"
)
func TestSSLEnabled(t *testing.T) {
initClients()
if client.HTTP == nil {
// No http.Client means the client defaults to SSL enabled
return
}
if client.HTTP.Transport == nil {
// No transport means the client defaults to SSL enabled
return
}
conf := client.HTTP.Transport.(*http.Transport).TLSClientConfig
if conf == nil {
// No TLSClientConfig means the client defaults to SSL enabled
return
}
if conf.InsecureSkipVerify {
t.Errorf("expected InsecureSkipVerify == false")
}
if pgclient.HTTP == nil {
// No http.Client means the pgclient defaults to SSL enabled
return
}
if pgclient.HTTP.Transport == nil {
// No transport means the pgclient defaults to SSL enabled
return
}
conf = pgclient.HTTP.Transport.(*http.Transport).TLSClientConfig
if conf == nil {
// No TLSClientConfig means the pgclient defaults to SSL enabled
return
}
if conf.InsecureSkipVerify {
t.Errorf("expected InsecureSkipVerify == false")
}
client = nil
pgclient = nil
}
func TestSSLDisable(t *testing.T) {
os.Setenv("HEROKU_SSL_VERIFY", "disable")
initClients()
if client.HTTP == nil {
t.Fatalf("client.HTTP not set, expected http.Client")
}
if client.HTTP.Transport == nil {
t.Fatalf("client.HTTP.Transport not set")
}
conf := client.HTTP.Transport.(*http.Transport).TLSClientConfig
if conf == nil {
t.Fatalf("client.HTTP.Transport's TLSClientConfig is nil")
}
if !conf.InsecureSkipVerify {
t.Errorf("expected InsecureSkipVerify == true")
}
if pgclient.HTTP == nil {
t.Fatalf("pgclient.HTTP not set, expected http.Client")
}
if pgclient.HTTP.Transport == nil {
t.Fatalf("pgclient.HTTP.Transport not set")
}
conf = pgclient.HTTP.Transport.(*http.Transport).TLSClientConfig
if conf == nil {
t.Fatalf("pgclient.HTTP.Transport's TLSClientConfig is nil")
}
if !conf.InsecureSkipVerify {
t.Errorf("expected InsecureSkipVerify == true")
}
os.Setenv("HEROKU_SSL_VERIFY", "")
client = nil
pgclient = nil
}
func TestHerokuAPIURL(t *testing.T) {
newURL := "https://api.otherheroku.com"
os.Setenv("HEROKU_API_URL", newURL)
initClients()
if client.URL != newURL {
t.Errorf("expected client.URL to be %q, got %q", newURL, client.URL)
}
if apiURL != newURL {
t.Errorf("expected apiURL to be %q, got %q", newURL, apiURL)
}
// cleanup
os.Setenv("HEROKU_API_URL", "")
}
func TestHerokuPostgresqlHost(t *testing.T) {
newHost := "maciek"
newURL := "https://" + newHost + ".herokuapp.com" + postgresql.DefaultAPIPath
os.Setenv("HEROKU_POSTGRESQL_HOST", newHost)
initClients()
if pgclient.URL != newURL {
t.Errorf("expected client.URL to be %q, got %q", newURL, pgclient.URL)
}
if pgclient.StarterURL != newURL {
t.Errorf("expected client.StarterURL to be %q, got %q", newURL, pgclient.StarterURL)
}
// cleanup
os.Setenv("HEROKU_POSTGRESQL_HOST", "")
}
func TestShogun(t *testing.T) {
newShogun := "will"
newURL := "https://shogun-" + newShogun + ".herokuapp.com" + postgresql.DefaultAPIPath
os.Setenv("SHOGUN", newShogun)
initClients()
if pgclient.URL != newURL {
t.Errorf("expected client.URL to be %q, got %q", newURL, pgclient.URL)
}
// starter URL should be unchanged
if pgclient.StarterURL != "" {
t.Errorf("expected client.StarterURL to be empty, got %q", pgclient.StarterURL)
}
// cleanup
os.Setenv("SHOGUN", "")
}
func TestShogunAndHerokuPostgresqlHost(t *testing.T) {
newShogun := "fdr"
newShogunURL := "https://shogun-" + newShogun + ".herokuapp.com" + postgresql.DefaultAPIPath
newHost := "maciek"
newHostURL := "https://" + newHost + ".herokuapp.com" + postgresql.DefaultAPIPath
os.Setenv("HEROKU_POSTGRESQL_HOST", newHost)
os.Setenv("SHOGUN", newShogun)
initClients()
if pgclient.URL != newShogunURL {
t.Errorf("expected client.URL to be %q, got %q", newShogunURL, pgclient.URL)
}
// starter URL should be unchanged
if pgclient.StarterURL != newHostURL {
t.Errorf("expected client.StarterURL to be %q, got %q", newHostURL, pgclient.StarterURL)
}
// TODO
// cleanup
os.Setenv("HEROKU_POSTGRESQL_HOST", "")
os.Setenv("SHOGUN", "")
}