Repository navigation
test: support recording REST API requests in acceptance tests [ENG-9440] - #268
Merged
Merged
Conversation
### what Extend the recorded transport to support REST requests, in addition to GraphQL ones. GraphQL requests are detected by the `query` field in the request body, and keep the existing recordings format. REST requests are recorded with method, path and body, and responses with status code and body. Also handle requests without a body. ### why Allow writing acceptance tests for resources and data sources based on the IaC API. ### testing Existing acceptance tests pass in replay mode with unchanged recordings. ### docs n/a
There was a problem hiding this comment.
All reported issues were addressed across 1 file
Architecture diagram
sequenceDiagram
participant Client as HTTP Client
participant RT as RecordedTransport
participant Recorder as Recorder/Player
participant RealAPI as Real API (record mode)
Note over Client,Recorder: Runtime flow for acceptance tests
Client->>RT: RoundTrip(request)
alt Request has body
RT->>RT: Read request body
else Request has no body
RT->>RT: Proceed without body
end
RT->>RT: newRecordedRequest() classify request
alt GraphQL request (query field present)
RT->>RT: Extract query + variables
else REST request
RT->>RT: Capture method + path + body
end
alt Record mode
RT->>RealAPI: Forward original request
RealAPI-->>RT: Response with status + body
RT->>RT: Parse response
alt GraphQL request
RT->>RT: Extract data + errors
else REST request
RT->>RT: Extract status code + body
end
RT->>Recorder: Save recording (request + response)
Recorder-->>RT: Recording stored
RT-->>Client: Return real response
else Replay mode
RT->>RT: Build request key
alt GraphQL request
RT->>RT: Key = query + variables
else REST request
RT->>RT: Key = method + path + compact body
end
RT->>Recorder: getRecording(key)
alt Recording found
Recorder-->>RT: Matching recording
alt REST request
RT->>RT: Construct response from status + body
else GraphQL request
RT->>RT: Verify query + variables match
RT->>RT: Construct GraphQL response
end
RT-->>Client: Return recorded response
else No recording found
Recorder-->>RT: Error
RT-->>Client: Return empty response + error
end
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
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.
ENG-9440
what
Extend the recorded transport to support REST requests, in addition to
GraphQL ones. GraphQL requests are detected by the
queryfield in therequest body, and keep the existing recordings format. REST requests are
recorded with method, path and body, and responses with status code and body.
Also handle requests without a body.
why
Allow writing acceptance tests for resources and data sources based on the
IaC API.
testing
Existing acceptance tests pass in replay mode with unchanged recordings.
docs
n/a