-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_test.go
More file actions
47 lines (37 loc) · 752 Bytes
/
init_test.go
File metadata and controls
47 lines (37 loc) · 752 Bytes
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
package twse
import (
"io/ioutil"
"net/http"
"strings"
)
var (
twseReal *Service
)
func init() {
client := GetClient()
var err error
twseReal, err = New(client)
if err != nil {
panic(err)
}
}
type TestTransport struct {
body string
statusCode int
}
// RoundTrip add apikey
func (t *TestTransport) RoundTrip(req *http.Request) (*http.Response, error) {
var res http.Response
res.StatusCode = t.statusCode
res.Body = ioutil.NopCloser(strings.NewReader(t.body))
res.Header = http.Header{}
res.Request = req
return &res, nil
}
func clientTest(body string, statuscode int) *http.Client {
transport := &TestTransport{body: body, statusCode: statuscode}
client := &http.Client{
Transport: transport,
}
return client
}