Correct context uses

`doAPI`'s `context` does not work due to `WithContext` immutability.
`Authenticate` and `RegisterApp` does not use `context` although they
needs `context`, so their `context` does not work also. This commit fixes
them and add test cases.
This commit is contained in:
TSUYUSATO Kitsune 2017-04-19 18:26:12 +09:00
parent 909a57c5ea
commit fb53d41dd9
5 changed files with 100 additions and 2 deletions

View file

@ -129,7 +129,7 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
} else {
req, err = http.NewRequest(method, u.String(), nil)
}
req.WithContext(ctx)
req = req.WithContext(ctx)
req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
if params != nil {
req.Header.Set("Content-Type", ct)
@ -191,6 +191,7 @@ func (c *Client) Authenticate(ctx context.Context, username, password string) er
if err != nil {
return err
}
req = req.WithContext(ctx)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := c.Do(req)
if err != nil {