Bring tests back up to 100%

Make a new method called parseResponse which essentially allows us to feed it our own response  so that we can feed it bad body so that it cannot unmarshal or even read it.
This commit is contained in:
Timothy Lock
2018-01-22 15:40:28 -05:00
parent fe51698284
commit 6d00842743
2 changed files with 37 additions and 50 deletions

View File

@@ -115,7 +115,10 @@ func (c *Client) Verify(req IAPRequest, result interface{}) error {
return err
}
defer resp.Body.Close()
return c.parseResponse(resp, result, client, req)
}
func (c *Client) parseResponse(resp *http.Response, result interface{}, client http.Client, req IAPRequest) error {
// Read the body now so that we can unmarshal it twice
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
@@ -134,7 +137,7 @@ func (c *Client) Verify(req IAPRequest, result interface{}) error {
return err
}
if r.Status == 21007 {
b = new(bytes.Buffer)
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(req)
resp, err := client.Post(c.SandboxURL, "application/json; charset=utf-8", b)
if err != nil {