forked from ihoukai/parse-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
53 lines (43 loc) · 883 Bytes
/
common_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
package parse
import (
"crypto/tls"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"
)
type ctxT struct {
ts *httptest.Server
oldHost string
oldHttpClient *http.Client
}
var ctx = ctxT{}
func setupTestServer(handler http.HandlerFunc) *httptest.Server {
ts := httptest.NewTLSServer(handler)
ctx.ts = ts
_url, err := url.Parse(ts.URL)
if err != nil {
panic(err)
}
ctx.oldHost = parseHost
ctx.oldHttpClient = defaultClient.httpClient
parseHost = _url.Host
defaultClient.httpClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
return ts
}
func teardownTestServer() {
ctx.ts.Close()
parseHost = ctx.oldHost
defaultClient.httpClient = ctx.oldHttpClient
}
func TestMain(m *testing.M) {
Initialize("app_id", "rest_key", "master_key")
os.Exit(m.Run())
}