0

I am trying to unit test an API which returns a CSV response. I am used to testing APIs that return Json response by doing something like this :

resBody := `{"access_token": "token","instance_url": "url","id": "id","token_type": "Bearer"}`
r := ioutil.NopCloser(bytes.NewReader([]byte(resBody)))

clientMock.GetMock = func(url string) (*http.Response, error) {
        return &http.Response{
            StatusCode: 200,
            Body:       r,
        }, nil
    }

Here, the resBody is my mocked Json response, however unable to figure out what would be an equivalent response structure for testing APIs that return csv response.

1 Answer 1

2

Never mind, able to figure it out now. Below can be used to mock CSV response :

resBody := `"access_token","instance_url","id","token_type"` + "\n" + `"token","url","id","Bearer"`
r := ioutil.NopCloser(bytes.NewReader([]byte(resBody)))

clientMock.GetMock = func(url string) (*http.Response, error) {
        return &http.Response{
            StatusCode: 200,
            Body:       r,
        }, nil
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.