mocha
mocha copied to clipboard
Response body from file content in `testdata/` directory
A pattern I currently follow for all my Go tests is to store JSON response bodies in e.g testdata/all_users.json or testdata/europe_users.json and so on.
The testdata directory is considered the idiomatic way to do this in Go.
It would be super convenient if I could do something like the following, with an error/failure if the file does not exist:
m := mocha.New(t).CloseOnCleanup(t)
m.Start()
m.AddMocks(mocha.
Get(expect.URLPath("/users")).
Reply(reply.OK().BodyFile("testdata/all_users.json)))
Currently I'm using a separate helper function to read the files and pass the string in using BodyString(...)