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

Official hato-fake repo? #11

Open
vincentjames501 opened this issue Apr 30, 2020 · 3 comments
Open

Official hato-fake repo? #11

vincentjames501 opened this issue Apr 30, 2020 · 3 comments

Comments

@vincentjames501
Copy link

It would be awesome if there could be an official hato-fake repo which would support intercepting requests.

Inspiration:
clj-http-fake
http-kit-fake

I think either adding a repo like this or updating the documentation to reflect recommend patterns would help complete the testing story of hato.

Thanks for the awesome lib!

@gnarroway
Copy link
Owner

Thanks for raising this.

I’ve had a look at the repos and I think if there is sufficient demand then a community supported hato version will be fine and I would be happy to mention it in the docs.

Personally I do not use this type of testing. I will typically put things that communicate externally (to an api, db etc) in a boundary namespace with a protocol.

  • the boundary itself will be covered by integration tests connecting to real instances, as well as unit tests if there is any interesting logic
  • business logic has these protocol implementations injected so for unit tests, the entire boundary can be mocked/stubbed, rather than the implementation (specifics of an HTTP request)
  • end to end tests will again typically use real instances, or if I really need some specific behavior from a dependency, I can spin up a fake instance and point to it.

Maybe these interceptor libraries would be useful for the end to end tests as described above, but since I do not use them I don’t really have a strong opinion on how such libraries would behave.

@onetom
Copy link

onetom commented Jun 6, 2022

Some example would be still great, so we can learn about these techniques by example.
I would be interested how you name your protocols?
How you make them namespace-reloading friendly?
How would test-specific mock implementations of these protocols would look like?

But regarding faking, I think turning the current hato.client/request* function a request option, similarly to the :http-client, would be a pretty good solution.
Then test-specific fakes could be implemented via clojure.core.match/match, which trivially supports features equivalent to spying, mocking and stubbing.

@onetom
Copy link

onetom commented Jun 6, 2022

On further thinking, it would be still nice to keep the functionality of a cookie jar in a fake implementation. In such cases, the faking with clojure.core.match wouldn't be that straightforward...

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

3 participants