7

A legacy app has the below working Gatling test

private val getUserByTuid = scenario("GetActiveUserInfoWrapper")
    .feed(users.toArray.circular)
    .exec(
      http("GET /v1/foo/{id}")
        .get("/v1/foo/${id}")
        .header("Content-Type", "application/json")
        .header("User-Agent", "gatling")
        .check(status is 200)
        .check(jsonPath("$..ID") exists)
    )

I need to change it such that either the status is 200, in which case it checks that jsonnode ID exists (just like above), or the status is 401, in which case it checks that jsonnode Description exists. Any other status should result in a failure.

This is what I have so far but it doesn't appear to be working as intended because Gatling considers all responses failures, even the ones that are 200 with ID and 401 with Description.

private val getUserByTuid = scenario("GetActiveUserInfoWrapper")
    .feed(users.toArray.circular)
    .exec(
      http("GET /v1/foo/{id}")
        .get("/v1/foo/${id}")
        .header("Content-Type", "application/json")
        .header("User-Agent", "gatling")
        .check(checkIf((response: Response, session: Session) => response.status.get.getStatusCode == 200)(jsonPath("$..ID") exists))
        .check(checkIf((response: Response, session: Session) => response.status.get.getStatusCode == 401)(jsonPath("$..Description") exists))
    )

I've looked at the docs and searched around the web but haven't been able to figure out the correct way to achieve what I want, thus asking here.

fred
  • 1,812
  • 3
  • 37
  • 57
  • 3
    Try `.check(status.in(200, 401))` before the subsequent checks. – Robert Bain Jul 16 '18 at 12:26
  • 1
    Does this answer your question? [How do you use Gatling's checkIf method?](https://stackoverflow.com/questions/51328868/how-do-you-use-gatlings-checkif-method) – Justin Wrobel Nov 05 '19 at 14:33
  • 1
    Just to add that `import io.gatling.core.Predef.value2Success` is required when using the `checkIf(condition: (R, Session) => Validation[Boolean])(thenCheck: C)` overload – Mark Tickner Apr 20 '21 at 13:49

0 Answers0