-
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
Redirecting requests to a mock server in @azure/arm-network@26.0.0 #25442
Comments
Hi @superneminator, I think the best way to do something like this would be to use the
The format for pipeline policies has changed slightly (they now have mandatory name properties in addition to a
Let me know if that all makes sense or if you have additional questions! |
@superneminator Jeff's right, after upgrading from v22 to v26, the way we add policy is changed. Simply speacking you could build your policy first(remember to install dependency @azure/core-rest-pipeline): function mockHeaderPolicyFactory(): PipelinePolicy {
return {
name: "mock header policy",
sendRequest: async (
request: PipelineRequest,
next: SendRequest
): Promise<PipelineResponse> => {
const actualArmEndpoint = await TestContext.getActualArmEndpoint();
request.headers.set(MockFx.Headers.RUN_ID, TestContext.getRunId());
request.headers.set(MockFx.Headers.TEST_ID, TestContext.getTestId());
request.headers.set(MockFx.Headers.ORIGINAL_HOST, actualArmEndpoint);
request.headers.set(MockFx.Headers.SOURCE, "ARMClient");
// Sanitize any URLs that might be going out to actual arm endpoint to
// direct them to mock server instead
if (request.url.toString().startsWith(actualArmEndpoint)) {
const mockServerUrl = `https://localhost:${TestConstants.MockFxPort}/`;
request.url = request.url.toString().replace(actualArmEndpoint, mockServerUrl);
}
const response = await next(request);
return response;
},
};
} And then add this policy into your options or your const client = new NetworkManagementClient(credential, subscriptionId, {
additionalPolicies: [{
policy: mockHeaderPolicyFactory(),
position: "perRetry",
}]
}); |
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you! |
Hi @MaryGao / @xirzec, after making the change you suggested, I started getting the following error:
To solve it, I had to make this change, as @tommyfrazier suggested. Now, everything works like a charm. Thank you all for helping me out with this. |
Glad it's working for you!
A few other options to consider:
|
We use the arm-network client in our test project and it works like a charm.
We now want to use the same client in the mock TS tests. For that, we have to redirect the traffic to a nodejs mock server.
The IaaS team managed to do that. They use the @azure/arm-network@22.0.0. As can be seen here and here, they achived that by using requestPolicyFactorie and adding 4 headers and modifying the endpoint.
We use a newer client version @azure/arm-network@26.0.0. This client has different optional parameters so the IaaS' solution doesn't work for us. I couldn't find an equivalent to requestPolicyFactories in the newer client version.
Question: how could we redirect requests in the new client version?
The text was updated successfully, but these errors were encountered: