WVAviator/capti

Local variable extraction

Closed this issue · 0 comments

Alongside the request and expect sections of a test suite, there should be an extract section as well. This section should work much like the expect section, but any variables used here will be populated, rather than read.

tests:
  - test: "sign in"
    description: "sign in test user for subsequent tests"
    request:
      method: POST
      url: "http://localhost:3000/signin"
      body:
        username: {TEST_USER_USERNAME} # these are read from existing env variables
        password: {TEST_USER_PASSWORD}
    expect:
      status: 2xx
    extract:
      headers:
        Authorization: Bearer {JWT_TOKEN} # this gets populated instead of read, can be used in subsequent requests

Extraction logic is subject to change - the above would be the most ideal if it is feasible. Conceptually, a parser could read the text before and after the variable, and match the response char by char. However, it could get tricky if the extracted variable contains the same text as text that comes after, for example if an extract matcher reads message: {GREETING} How are you? and for some reason the extract variable GREETING contains the word "How", how can the logic be arranged to avoid the collision? Maybe two pointers, reading chars backwards and forwards, and then grabbing the remainder as a trimmed slice?