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

mappings API needs some love #115

Open
ghost opened this issue Jul 2, 2020 · 2 comments
Open

mappings API needs some love #115

ghost opened this issue Jul 2, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 2, 2020

File definitions seem to be ok, but working with API is almost impossible. Simple example:

docker run --rm -p 8082:8082 -p 8083:8083 jordimartin/mmock`
> curl -d '{"request": {"method": "GET", "path": "/foo"}, "response": {"statusCode": 200}}' -X POST http://localhost:8082/api/mapping/foo 
> {"result":"created"}

Is it really created?

2020/07/02 22:38:08 Changes detected in mock definitions  DIRECTORY "config" WRITE [/config]
2020/07/02 22:38:08 Error Not valid config reader found. Loading config: /foo

I don't speak go to troubleshoot this but let's try something very naive:

> curl -d '{"request": {"method": "GET", "path": "/foo"}, "response": {"statusCode": 200}}' -X POST http://localhost:8082/api/mapping/foo.json
> {"result":"created"}

Logs:

2020/07/02 22:39:22 Loading config file: /config/foo.json
2020/07/02 22:39:22 Invalid mock format in: /config/foo.json Err: invalid value for delay, got: map[string]interface {}
2020/07/02 22:39:22 Error invalid value for delay, got: map[string]interface {}. Loading config: /foo.json

I don't think swagger.json even mentiones this endpoint BTW.

I thought you should know

@mcintyre94
Copy link
Contributor

I've seen something similar on delay - I think it's because something internal converts it from 2s (for example) to {"delay": 2000000}. Seems like that's happening before something that tries to validate the delay as a string in the right format.

@leon-id
Copy link

leon-id commented Jul 31, 2020

I've made POST and PUT api/mapping endpoints to work okay with JSON definitions (with some drawbacks, but I'm completely newbie in golang), as well as I've tried to fix delays handling in my fork (https://github.com/leon-id/mmock), so you could try your usecases.
It is necessary to add .json to mock name, and you should directly declare URI in mock definition:
curl -d '{"URI":"foo.json", "request": {"method": "GET", "path": "/foo"}, "response": {"statusCode": 200}}' -X POST http://localhost:8082/api/mapping/foo.json

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

2 participants