smocker
smocker copied to clipboard
Add a way to read and initialize mocks from a directory
Hi,
First of all, I really liked your project. Compared to similar solutions like Wiremock, this tool seems much more modern and easy to use. We are considering to use it in our microservices architecture to replace third-party services with a mock implementation on dev/qa environments to save money and make testing easier.
We want to be able to make a Docker image containing our mocks. To do that we would need Smocker to read mocks from a directory on initialization, like Wiremock does. I see #214 contains exactly what we need. Are there any plans to implementing this feature?
I saw in another ticket that someone suggested using the API to import the mocks, but that is not practical to us since we are in a k8s environment, ideally Smocker would load the mocks from a folder on startup and the environment would be ready to serve the mock requests.
Here is what I imagine:
smocker --mocks-directory=/opt/mocks
A problem may arise in cases where smocker already has some data and we want to import from --mocks-directory
, for example, a crash restart where Smocker will attempt to import the mocks again. I think you could do one of the following:
- In case smocker already has some data you could create a new session and add the mocks in
--mocks-directory
to it? - You could have another cli argument indicating if we should wipe the data on startup
- Just wipe the data if
--mocks-directory
has a value.
Thank you for your time!
First of all, I really liked your project
Thanks <3
Are there any plans to implementing this feature?
Yes. We're currently in the middle of a rework that will change Smocker internals (#210) but after that we'll look into adding this feature. Note however that the already existing --persistence-directory
parameter can answer this need and more (it can load full sessions, not just mocks).
A problem may arise in cases where smocker already has some data
We'll need to think about that for sure, I don't have a preferred solution yet
Thank you for the detailed response! Glad to hear Smocker is being actively improved :)
I saw --persistence-directory
when digging through the source code, but I noticed that Smocker generates a .db file inside that directory. Perhaps we could ship that file in the docker image and cp it into --persistence-directory
before startup to reset the database. Although a .db file is a bit harder to maintain and extend, it should work.
Yeah this is because of an issue on our side, we accidentally overwrote the docker latest with the storm-preview
tag, so the latest currently tags a preview image. If you use the 0.16.4 specifically, the persistence directory stores the sessions as a yaml file, not as a .db file. I'll fix the latest asap
Docker latest is fixed, it now correctly aliases 0.16.4, you can try again with the persistence directory :)
Wow, that was really fast! Thank you! I will try it later today!
Sorry for the late reply, I tested it today, it did generate yaml files the files contain internal metadata and some fields slightly changed. Either way I managed to a docker-compose volume to sync those files to my filesystem and used the UI to manage the mocks.
Firstly I just wanted to second the praise that Felipe gave for the project and to thank you for all the work that's been put into it.
I am just curious if there is any update on whether Smocker will include a means to load mocks from a directory on startup without having to compile a session.yml in the persistence directory?
hoping to use smocker for E2E testing and this feature would be incredibly useful