Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response body from file content in testdata/ directory #59

Open
zx8 opened this issue Sep 4, 2023 · 0 comments
Open

Response body from file content in testdata/ directory #59

zx8 opened this issue Sep 4, 2023 · 0 comments

Comments

@zx8
Copy link

zx8 commented Sep 4, 2023

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(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant