# Functional / smoke testing — Artillery's `functional-testing-with-expect` +
# `table-driven-functional-tests`.
#
# loadr doubles as a functional tester: make one pass over a table of cases
# (data feeder with `on_eof: stop`), assert each response, and let the run exit
# non-zero if a single check fails (`checks: rate>=1.0`). Drop it straight into
# CI as a contract/smoke gate — no separate test framework needed.
#
#   loadr run examples/41-functional-test.yaml   # exit code 99 on any failed check
name: functional-test
description: one pass over a case table, fail the run on any failed assertion

defaults:
  http:
    base_url: https://api.example.com

data:
  cases:
    type: csv
    path: data/users.csv
    mode: shared
    on_eof: stop      # one pass over the table, then the VU retires

scenarios:
  smoke:
    executor: shared-iterations
    vus: 4
    iterations: 1000   # upper bound; the feeder stops the run at table size
    flow:
      - request:
          name: login
          method: POST
          url: /login
          body: { form: { username: "${data.cases.username}", password: "${data.cases.password}" } }
          checks:
            - { type: status, equals: 200 }
            - { type: jsonpath, expression: "$.token", exists: true }
      - request:
          name: whoami
          url: /me
          headers: { Authorization: "Bearer ${token}" }
          checks:
            - { type: status, equals: 200 }
            - { type: jsonpath, name: identity, expression: "$.username", equals: "${data.cases.username}" }

thresholds:
  # Functional mode: every check must pass or the run fails (non-zero exit).
  checks: [ "rate>=1.0" ]
