Wiremock录制-在录制模式下“即时”重写响应

时间:2018-10-19 10:33:52

标签: java mocking wiremock

我有一个wiremock实例,如下例所示:

UITableView

现在,当我开始在localhost:8080 / __ admin / recorder /上为域java -jar wiremock-standalone-2.19.0.jar --port=8080 --root-dir="/data" --proxy-all="https://api.github.com" --verbose 进行记录并请求这样的代理URL

https://api.github.com/repos/MyOrganisationName/MyRepoName/contents/

我收到以下答复:

https://api.github.com

现在的“问题”是我也要关注这些网址,例如 [ { "name": "a-file-in-my-repo.md", "path": "content/articles/a-file-in-my-repo.md", "sha": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", "size": 0, "url": "https://api.github.com/repos/MyOrganisationName/MyRepoName/contents/content/articles/a-file-in-my-repo.md?ref=develop", "html_url": "https://github.com/MyOrganisationName/MyRepoName/blob/develop/content/articles/a-file-in-my-repo.md", "git_url": "https://api.github.com/repos/MyOrganisationName/MyRepoName/git/blobs/e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", "download_url": "https://raw.githubusercontent.com/MyOrganisationName/MyRepoName/develop/content/articles/a-file-in-my-repo.md", "type": "file", "_links": { "self": "https://api.github.com/repos/MyOrganisationName/MyRepoName/contents/content/articles/a-file-in-my-repo.md?ref=develop", "git": "https://api.github.com/repos/MyOrganisationName/MyRepoName/git/blobs/e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", "html": "https://github.com/MyOrganisationName/MyRepoName/blob/develop/content/articles/a-file-in-my-repo.md" } } ] -但是直接针对github api执行请求,而不是通过配置的Wiremock代理执行请求。

因此,我需要一些重写/替换功能(在Wiremock级别上),以便在持续记录之前将url匹配的https://api.github.com重写为http://localhost:8080,以便得到如下响应:

https://api.github.com/repos/MyOrganisationName/MyRepoName/contents/content/articles/a-file-in-my-repo.md?ref=develop

以某种方式无需每次手动更换和重新启动Wiremock即可吗?

预先感谢

1 个答案:

答案 0 :(得分:0)

Wiremock不会关心http://localhost:8080http://github.com,因为如果端点匹配,它将已经在重写它们。

如果按预期方式进行设置,则仍将必须为Wiremock提供自定义映射,以提供正确的响应。

您能否详细说明为什么要替换网址?

要尝试回答您的问题的一部分,我不知道一种在初始代理期间转换映射响应的方法,但是您可以使用OpenTable's Wiremock Body Transformer之类的方法对录音进行消毒,以便它们如何工作您想要在以后的播放中。