-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_test.go
62 lines (49 loc) · 1.1 KB
/
init_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
package gotd
import (
"io/ioutil"
"net/http"
"strings"
)
const (
redirectURL = "http://localhost:8090"
clientsecretPath = "./instance/client_secret.json"
)
// account setting please reference to init_test_secret.go.sample
var (
// if true, test online
onlineTest = true
tdReal *Service
)
func init() {
if !onlineTest {
return
}
auth := NewAuth()
auth.SetTLS("./instance/cert.pem", "./instance/key.pem")
client := auth.GetClient(clientsecretPath, "TDAmeritrade-go.json")
var err error
tdReal, 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
}