Skip to content

[#1032] Added mock server integration#1097

Merged
adamw merged 9 commits intosoftwaremill:masterfrom
vitaliihonta:feature/1032
May 4, 2021
Merged

[#1032] Added mock server integration#1097
adamw merged 9 commits intosoftwaremill:masterfrom
vitaliihonta:feature/1032

Conversation

@vitaliihonta
Copy link
Copy Markdown

@vitaliihonta vitaliihonta commented Mar 22, 2021

@adamw @ghostbuster91 added DRAFT implementation with mock-server .
You may try it by running mock-server locally in docker:

 docker run -d --name tapir-mock-server --rm -p 1080:1080 mockserver/mockserver

There are few questions about the implementation:

  • I decided to communicate with the mock-server directly using REST API (so there are no dependency on java client which transitively depends on netty which may be an issue)
  • It is required to use some json library to communicate with mock-server. What option should be choosed? Should we abstract over the library using tapir's JsonCodec
  • How can we add tests? Would it be OK to use test-containers in CI to be sure? Or can it be just unit tests?

Comment thread build.sbt

val response = {
val responseValue = expectedOutput.merge
val encodeOutputBody: EncodeOutputBody[Any, Any, Nothing] = new EncodeOutputBody[Any, Any, Nothing] {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can be refactored so that both sttp-stub-server and sttp-mock-server will use the same logic

@vitaliihonta
Copy link
Copy Markdown
Author

I have no idea why doesn't it compile on the CI server 😢 Locally it runs successfully

@adamw
Copy link
Copy Markdown
Member

adamw commented Apr 9, 2021

I think using the REST API directly is definitely a good choice :) Same with circe - it doesn't bring in many dependencies so it's also a safe (and popular) choice.

As for the compile errors - maybe you rebased before pushing? There have been some changes to server interpreters, see the stub implementation (but shouldn't impact your impl much)

@vitaliihonta
Copy link
Copy Markdown
Author

@adamw got it, I'll rebase my branch soon.
BTW about the tests. Actually, I can cover basic cases with just unit tests without testcontainers. It's not as reliable as integration tests with the latest mock-server version in docker, but it's a good start.

Comment thread server/sttp-mock-server/src/main/scala/sttp/tapir/server/mockserver/model.scala Outdated
@vitaliihonta
Copy link
Copy Markdown
Author

@adamw @ghostbuster91 I've added the most used functionality (creating strict expectations, verifying them, clearing, etc.). I would like to receive your feedback before I go further implementing tests 😄
P.S. Not sure why JVM suites timeouts...

@adamw
Copy link
Copy Markdown
Member

adamw commented Apr 26, 2021

Looks good - I don't think I have any significant comments :)

@adamw
Copy link
Copy Markdown
Member

adamw commented Apr 26, 2021

I guess for unit-testing you might end up stubbing the mock server ;)

@ghostbuster91
Copy link
Copy Markdown
Contributor

Awesome, thanks for the great work :) I think we should also mention it somewhere in the docs, probably in testing section (https://github.com/softwaremill/tapir/blob/master/doc/testing.md)

@vitaliihonta vitaliihonta changed the title DRAFT [#1032] Added draft mock server integration [#1032] Added draft mock server integration Apr 30, 2021
@vitaliihonta
Copy link
Copy Markdown
Author

@adamw @ghostbuster91 I'm done with unit tests and the documentation 😃
I hope it's OK so that you can merge it

@vitaliihonta vitaliihonta changed the title [#1032] Added draft mock server integration [#1032] Added mock server integration Apr 30, 2021
@adamw adamw merged commit fd56b0c into softwaremill:master May 4, 2021
@adamw
Copy link
Copy Markdown
Member

adamw commented May 4, 2021

Thank you!

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

Successfully merging this pull request may close these issues.

3 participants