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

Reset in WireMock admin API not working fine. #372

Closed
beloquintana opened this issue Oct 30, 2019 · 24 comments
Closed

Reset in WireMock admin API not working fine. #372

beloquintana opened this issue Oct 30, 2019 · 24 comments
Assignees
Labels

Comments

@beloquintana
Copy link

Reset service should reset all mappings, but it delete all stub mappings.

How could I reset mappings via web API ?

@StefH
Copy link
Collaborator

StefH commented Oct 30, 2019

What do you expect when you reset the mappings?

(Or do you ask this for scenarios?)

@beloquintana
Copy link
Author

When I reset the mappings, I expect that every change in the stub mappings will be applied.

For example to add a new stub mapping, I create the mappings file, then I have to reset my wiremock service to have these changes.

I think that is better to use the Admin API to reset mappings changes that reset the wiremock service.

@StefH
Copy link
Collaborator

StefH commented Oct 30, 2019

Not quite sure if I follow, could it be that you want to:

  • create some static mapping json files
  • start wiremock
  • add some more mappings
  • do a reset
  • only the new mappings are deleted. The static mappings which were present during start of wiremock should still be there

?

@beloquintana
Copy link
Author

I want to:

  • create some static mapping json files
  • start wiremock
  • add some more mappings in my folder (new mappings are not added in wiremock server)
  • do a reset using Admin API to update wiremock server with the new mappings
  • new mappings and old mapping should be there

The new mappings are not added to wiremock If I do not reset my wiremock service (without using Admin API).

My mapping folder is like:

  • Mappings
    • API1
      • Test1
        • mapping1.json
      • Test2
        • mapping2.json
    • API2
      • Test1
        • mapping1.json
      • Test2
        • mapping2.json

@StefH
Copy link
Collaborator

StefH commented Oct 30, 2019

Ah I see. I am not sure if the mapping json files are found if these are present in sub folders. Did you try to copy the files directly in the mapping a folder?

@beloquintana
Copy link
Author

beloquintana commented Oct 31, 2019

The mapping json files are found when I reset the Wiremock server, but not when I call reset from Admin API.

@StefH
Copy link
Collaborator

StefH commented Oct 31, 2019

when I reset the Wiremock server, --> do you mean you just restart the WireMock server?

@beloquintana
Copy link
Author

Yes, I also implemented a custom IFileSystemHandler, but the point is how to update the mappings with the new changes without restart the WireMock server.

@StefH
Copy link
Collaborator

StefH commented Oct 31, 2019

  • the EnhancedFileSystemWatcher which is used to detect changes, can only read from the FileSystemHandler.GetMappingFolder() folder. Adding a configuration setting to also read recursive folders could be a solution for your problem

  • Adding a Admin API call like "Refresh" / "RefreshStaticMappings" which calls the FileSystemHandler.EnumerateFiles(...) would also be a solution for your question.

@beloquintana
Copy link
Author

Great!!, I think that both solution will be very useful.

@StefH
Copy link
Collaborator

StefH commented Oct 31, 2019

I keep this issue open until it's fixed.

@StefH StefH reopened this Oct 31, 2019
@StefH StefH self-assigned this Oct 31, 2019
@StefH
Copy link
Collaborator

StefH commented Oct 31, 2019

You can try new package from MyGet:
WireMock.Net.1.0.37-ci-12144.nupkg

And set WatchStaticMappingsInSubdirectories to true in the settings.

@beloquintana
Copy link
Author

I tested WireMock.Net.1.0.37-ci-12144.nupkg and I find this bug:

New mappings are added, but It never delete the old changes until I restart WireMock server.

Steps to reproduce:

  1. create a static mapping json files with name map1.json
  2. start wiremock
  3. add a mapping in sub folders with name map2.json
    (map2.json is added correctly to wiremock)
  4. edit map2.json

Actual Result:
Wiremock shows 3 mappings:
map1
map2 old version
map2 new version

Expected Result:
Wiremock shows 2 mappings:
map1
map2 new version

@StefH
Copy link
Collaborator

StefH commented Nov 1, 2019

Question, for step 4; how do you edit map2.json ? Via an editor directly? Or via a PUT on the admin interface?

@beloquintana
Copy link
Author

Via a text editor directly

@StefH
Copy link
Collaborator

StefH commented Nov 1, 2019

This is a different thing.

If you just have a mapping file named map1.json, and this file does not define the Guid property, a new mapping is added when you edit this file in an editor.

There are 2 solutions for this:

  1. Rename the file to 791a3f31-6946-4ce7-8e6f-0237c7443275.json
  2. Define the Guid in the mapping json like: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.NETCoreApp2/__admin/mappings/791a3f31-6946-4ce7-8e6f-0237c7443275.json#L2

@StefH
Copy link
Collaborator

StefH commented Nov 1, 2019

#374

@beloquintana
Copy link
Author

Thanks for the WatchStaticMappingsInSubdirectories.

I think that define a Guid in a text editor is tricky and it is not intuitive.
If we could define an Id without any restriccion (Example: string id) would be easy to add and edit mapping json files via text editor.

Would it be possible to do?

@StefH
Copy link
Collaborator

StefH commented Nov 1, 2019

Sorry. The internal logic is using these guids.

Normally when adding a mapping via the admin API, the guid is assigned and stored in the mapping file when it's saved. Also when proxying, the guide is defined.

@StefH
Copy link
Collaborator

StefH commented Nov 2, 2019

I've also added an extra parameter to the Reset API method:

ResetMappingsAsync(bool? reloadStaticMappings = false);

POST example = to http:https://{{wm_hostname}}/__admin/mappings/reset?reloadStaticMappings=true

Which will reload the static mappings after a reset (=delete) from the mappings.

A preview NuGet can be found at MyGet --> WireMock.Net.1.0.37-ci-12153.nupkg

@StefH
Copy link
Collaborator

StefH commented Nov 5, 2019

Is this ok?

@beloquintana
Copy link
Author

This change is only for WireMock.Net.StandAlone?

WireMock.Net.1.0.37-ci-12153.nupkg is the StandAlone

@StefH
Copy link
Collaborator

StefH commented Nov 6, 2019

Both nuget packages should be there with that 1.0.37-ci-12153 identifier.

In your case, for testing you can use either package.

@beloquintana
Copy link
Author

It is work very well! I will use this functionality a lot.
Thanks you!!!

@StefH StefH closed this as completed Nov 7, 2019
@StefH StefH removed the question label Nov 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants