-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Unified Recorder] Support "variables" in recordings with proxy-tool #18585
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, should probably have a JS specialist give the final approval
@@ -181,6 +203,10 @@ export class TestProxyHttpClient { | |||
const req = this._createRecordingRequest(stopUri); | |||
req.headers.set("x-recording-save", "true"); | |||
|
|||
if (isRecordMode()) { | |||
req.headers.set("Content-Type", "application/json"); | |||
req.body = JSON.stringify(variables ?? this.variables); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn’t this mean that we’re setting req.body
to undefined if there are no variables? Is that desired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's clever and the implementation seems very simple. Since the variables are sent as JSON, I wonder why we can't store more than just strings. For example, I might like to store a number or even a nested object.
If you're interested in that idea, we can explore how the consumers of this API can strongly type that.
@@ -151,6 +170,9 @@ export class TestProxyHttpClient { | |||
throw new RecorderError("No recording ID returned for a successful start request."); | |||
} | |||
this.recordingId = id; | |||
if (isPlaybackMode()) { | |||
this.variables = !rsp.bodyAsText ? {} : JSON.parse(rsp.bodyAsText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.variables = !rsp.bodyAsText ? {} : JSON.parse(rsp.bodyAsText); | |
this.variables = JSON.parse(rsp.bodyAsText ?? "{}") as Record<string, string>; |
Is the body not automatically parsed given the content type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that happens in the deserializationPolicy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't checked,
recorder.variables["random-2"] = "known-string"; | ||
} | ||
|
||
await makeRequestAndVerifyResponse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what this is verifying? I see a variable is set, the variable is used in the request path, and test server seems always return "I am the answer!" but am not clear what's involved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, in playback mode, these variables will be available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makeRequestAndVerifyResponse
is a generic method and is applied for all the tests in this test suite.
It was initially created for the rest of the tests in the describe block.
All it does is make the request and check the response with what we are supposed to get.
All tests are run in the record, playback, and live modes in sequence in the same run.
The idea of the test is that the random string won't change in playback mode, and it'll reuse whatever has been created in the record mode.
Any suggestions on how I can make this clear? or improve the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine. setting is in record mode but reading is in playback mode so I don't think there is a straight-forward way to test them as a whole. but end-to-end is working so we are good.
Co-authored-by: Will Temple <witemple@microsoft.com>
Co-authored-by: Will Temple <witemple@microsoft.com>
Co-authored-by: Will Temple <witemple@microsoft.com>
…u/azure-sdk-for-js into harshan/issue/18580
I did try to support numbers, but proxy-tool seems to be doing some validation on its end which is failing for numbers. So, kept strings only as of now. I provided the info to Scott. We'll see once the proxy tool's support improves.
I was thinking in those lines but as we only support strings at the moment, not much is needed at the moment. Tracking your comments in the epic #15829 for now. |
Issue #18580
What?
Allows storing the dynamically created variables in the record mode. Recorder registers the variables as part of the recording. Using the "variables" in playback mode would give the key-value pairs that are stored in record mode.
Example:
Use this
recorder.variables["random-1"]
wherever you'd like to use in your test after the if-block.(This would work in all three modes - record/playback/live just by adding the if-block above)
Internals(How does it work?):