Skip to content

feat(request): substitute {{.Random}} patch token with a random string - #243

Merged
Liyu Ma (liyu-ma) merged 4 commits into
mainfrom
maliyu/patch-random-body
Aug 26, 2026
Merged

feat(request): substitute {{.Random}} patch token with a random string#243
Liyu Ma (liyu-ma) merged 4 commits into
mainfrom
maliyu/patch-random-body

Conversation

@liyu-ma

@liyu-ma Liyu Ma (liyu-ma) commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Specify a placeholder which allows a random string to be injected for Patch request body.
  • Update the RequestPatch.Body doc comment in api/types/load_traffic.go accordingly.

Behavior

  • The literal token {{.Random}} in a patch body is replaced on every request with a fresh random string, guaranteeing each patch is a real mutation (bumps resourceVersion, emits watch events) rather than a no-op.
  • A body without the token is sent unchanged (backward compatible).

Test plan

  • go build ./...
  • go test ./request/ — updated tests assert the placeholder is replaced, bodies differ across renders, and rendering is concurrency-safe (16×100 distinct bodies)

Replace the monotonically-increasing counter with a random lowercase
string so the placeholder name matches its behavior. Drops the per-builder
patchCounter and uses crypto/rand + math/big already imported.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates PATCH request body rendering so the {{.Random}} placeholder is replaced per request with a random lowercase string, ensuring each PATCH is a real mutation rather than a repeated no-op. It also updates the public API documentation to describe this behavior and adds tests around rendering and concurrency behavior.

Changes:

  • Add {{.Random}} placeholder support in patch bodies via per-request rendering.
  • Replace the prior patch-body storage with a raw body template string and render on each Build().
  • Add unit tests for placeholder replacement and concurrent rendering; update RequestPatch.Body documentation accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
request/random.go Adds patch-body placeholder constant, body rendering, and random string generation used per PATCH request.
request/random_test.go Adds unit tests for placeholder replacement, uniqueness, and concurrent rendering behavior.
api/types/load_traffic.go Updates RequestPatch.Body doc comment to document {{.Random}} per-request substitution.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread request/random_test.go
Comment thread request/random.go Outdated
Comment thread request/random.go Outdated
Comment thread request/random.go Outdated
Drop the duplicate randomString helper and render patch bodies with the
existing randomPayload (uniform [a-zA-Z0-9], rejection-sampled). Add a
TestRandomPayload covering length, charset, empty-on-n<=0, and uniqueness.
Comment thread request/random.go Outdated

@xinWeiWei24 xinWeiWei24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@liyu-ma
Liyu Ma (liyu-ma) merged commit a13c14d into main Aug 26, 2026
4 checks passed
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.

4 participants