# Data-driven login: each iteration takes the next row from users.csv
# (shared cursor across all VUs, wrapping at EOF).
name: data-driven-login
description: CSV-parameterized login flow

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

data:
  users:
    type: csv
    path: data/users.csv
    mode: shared       # all VUs share one cursor (per_vu: each VU gets its own)
    on_eof: recycle    # wrap around (stop: retire the VU)

scenarios:
  login_flow:
    executor: per-vu-iterations
    vus: 5
    iterations: 20
    flow:
      - request:
          name: login
          method: POST
          url: /login
          body:
            form:
              username: ${data.users.username}
              password: ${data.users.password}
          extract:
            - { type: jsonpath, name: token, expression: "$.token" }
          assert:
            - { type: status, equals: 200 }
            - { type: jsonpath, expression: "$.token", exists: true }
      - request:
          name: profile
          url: /me
          headers:
            Authorization: Bearer ${token}
          checks:
            - { type: status, equals: 200 }
            - { type: jsonpath, name: correct user, expression: "$.username", equals: "${data.users.username}" }

thresholds:
  checks: [ "rate>0.99" ]
