feat: capture mock request fields into test variables (v1 backport)#326
Merged
Merged
Conversation
Add `variablesToSet` to mock definitions: values of the incoming
request (JSON body, query, headers) are extracted with the template
syntax of the template reply strategy ({{ .request.* }}) and become
available to subsequent tests via {{ $varName }}.
- works on nested definitions of composite strategies
(uriVary, methodVary, sequence, basedOnRequest)
- `fromCall: first|last` selects the call to capture from when the
definition is called multiple times (default: last)
- variables from the test response take precedence on name collision
- add {{ .request.Header "name" }} to the mock template context
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.
Backport of #325 to the
v1line.What
Adds
variablesToSetto mock definitions: values of the incoming request (JSON body, query, headers) are extracted with the template syntax of thetemplatereply strategy ({{ .request.* }}) and become available to subsequent tests via{{ $varName }}.Details
uriVary,methodVary,sequence,basedOnRequest)fromCall: first|lastselects the call to capture from when a definition is called multiple times (default:last)requestConstraints; a missing JSON field is a test errorvariables_to_settakes precedence over a mock-captured value{{ .request.Header "name" }}to the mock template contextBackport note
Same change as #325, adapted to the pre-
goccy/go-yamlloader onv1(map[interface{}]interface{}mock definitions). Tests and docs identical.See #325 for the full description.