feat(request): substitute {{.Random}} patch token with a random string - #243
Merged
Conversation
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.
There was a problem hiding this comment.
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.Bodydocumentation 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.
xinWeiWei24
reviewed
Aug 24, 2026
xinWeiWei24
reviewed
Aug 24, 2026
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.
xinWeiWei24
reviewed
Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RequestPatch.Bodydoc comment inapi/types/load_traffic.goaccordingly.Behavior
{{.Random}}in a patchbodyis 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.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)