https://linen.dev logo
Title
t

Terry

02/10/2023, 7:33 PM
Hi everyone, I'm using wiremock to stub a response and I'm having trouble with request matching.
stubFor(any(urlPathEqualTo("/everything"))
  .withQueryParam("search_term", equalTo("WireMock"))
  .withQueryParam("search_term", equalTo("Wireshark"))
I have a stub like this that works fine initially, but when I make another stub that would change out "WireMock" for something else like "HungryAnts", it would still make the response for the above stub. So I'm wondering should I use equalTo or something else when I use queryParam? I want my stub to go to the exact file that has this specific url.
t

Tom

02/10/2023, 8:53 PM
Hi Terry, are you actually calling
withQueryParam(…)
twice on one stub for the same parameter name? That won’t work - the second call will overwrite the first. If you create two separate stubs that are the same but with different values inside
equalTo(…)
I think this will do what you’re looking for.
t

Terry

02/10/2023, 9:07 PM
The endpoint is supposed to look similar to this /id=111&id=222 /id=111,222 I didn't know how to go about simulating multiple query parameter of the same name
t

Tom

02/10/2023, 9:23 PM
Do you need to say id must = 111 AND id must = 222 for the match to happen? If so, this isn’t possible at the moment, but there is a PR in the works to make it so. If just the 222 value on its own is enough however, you can just specify that and it’ll match even if it’s not the only value of id.
t

Terry

02/10/2023, 11:09 PM
Awesome, that's understandable. I think I'll try to use a work around to get by. Thank you for helping me out!
t

Tom

02/11/2023, 5:27 PM
No worries!