Skip to content

Resolve {{ index }} in a plain request (fixes #186)#231

Closed
fcsonline wants to merge 1 commit into
masterfrom
fix/186-index-plain-request
Closed

Resolve {{ index }} in a plain request (fixes #186)#231
fcsonline wants to merge 1 commit into
masterfrom
fix/186-index-plain-request

Conversation

@fcsonline

Copy link
Copy Markdown
Owner

Problem (#186)

{{ index }} only existed inside with_items / with_items_range / with_items_from_csv / with_items_from_file expansions, where it is the item's position in the list. In a plain request the variable was never set, so a plan referencing {{ index }}:

  • panicked in the default strict mode (Unknown 'index' variable), or
  • interpolated to an empty string under --relaxed-interpolations.

Fix

Seed index with the iteration counter when each iteration's context is built in run_iteration, so a plain request resolves {{ index }} to the iteration number. Expanded requests still override index with their list position at execute time, so with_items semantics are unchanged.

iterations: 3,      GET /idx/{{ index }}            -> /idx/0  /idx/1  /idx/2   (was: panic)
with_items:[a,b,c]  GET /{{ item }}/{{ index }}     -> /a/0  /b/1  /c/2         (unchanged)

Notes

Minimal change (2 lines). Verified against the exact repro from #186 (previously panicked, now runs clean) and cargo fmt / cargo clippy -- -D warnings / cargo test (61) all pass.

Inspired by zoosky/driller#26, trimmed to just the core fix.

Seed `index` with the iteration counter when building each iteration's
context, so `{{ index }}` resolves in a plain request instead of panicking
with "Unknown 'index' variable" in strict mode (or interpolating to an empty
string under --relaxed-interpolations).

with_items / csv / file / range expansions still override `index` with the
item's list position at execute time, so their semantics are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant