Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk/test-utils/recorder-new/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 1.0.0 (Unreleased)

## 2021-12-14

- Add `configureClient` method to the `TestProxytHttpClient` to allow instrumenting the client with the recorder policy which helps in enabling the recorder to redirect the requests of your tests to the proxy tool.
- Also un-exports `recorderHttpPolicy` function.
[#19362](https://github.com/Azure/azure-sdk-for-js/pull/19362)

## 2021-12-13

- Add support for `setMatcher`, which can be used to instruct the proxy tool to ignore headers (using `HeaderlessMatcher`) or the request body (using `BodilessMatcher`) when matching requests to recordings.
Expand Down
13 changes: 12 additions & 1 deletion sdk/test-utils/recorder-new/src/core-v2-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
createPipelineRequest,
HttpClient,
HttpMethods,
Pipeline,
PipelinePolicy,
PipelineRequest,
PipelineResponse,
SendRequest
} from "@azure/core-rest-pipeline";
import { isPlaybackMode, isRecordMode } from "@azure-tools/test-recorder";
import { isLiveMode, isPlaybackMode, isRecordMode } from "@azure-tools/test-recorder";
import {
ensureExistence,
getTestMode,
Expand Down Expand Up @@ -255,6 +256,16 @@ export class TestProxyHttpClient {
}
return req;
}

/**
* For core-v2 - libraries depending on core-rest-pipeline.
* This method adds the recording policy to the input client's pipeline.
*/
public configureClient(client: { pipeline: Pipeline }): void {
if (!isLiveMode()) {
client.pipeline.addPolicy(recorderHttpPolicy(this));
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/recorder-new/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export { recorderHttpPolicy, TestProxyHttpClient } from "./core-v2-recorder";
export { TestProxyHttpClient } from "./core-v2-recorder";
export { TestProxyHttpClientCoreV1 } from "./core-v1-recorder";
export { relativeRecordingsPath } from "./utils/relativePathCalculator";
export { SanitizerOptions, RecorderStartOptions } from "./utils/utils";
Expand Down
4 changes: 2 additions & 2 deletions sdk/test-utils/recorder-new/test/testProxyTests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PipelineRequestOptions
} from "@azure/core-rest-pipeline";
import { ServiceClient } from "@azure/core-client";
import { recorderHttpPolicy, TestProxyHttpClient } from "../src";
import { TestProxyHttpClient } from "../src";
import { expect } from "chai";

type TestMode = "record" | "playback" | "live" | undefined;
Expand Down Expand Up @@ -56,7 +56,7 @@ function getTestServerUrl() {
beforeEach(async function() {
recorder = new TestProxyHttpClient(this.currentTest);
client = new ServiceClient({ baseUri: getTestServerUrl() });
client.pipeline.addPolicy(recorderHttpPolicy(recorder));
recorder.configureClient(client);
});

afterEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

import { env, isPlaybackMode } from "@azure-tools/test-recorder";
import { TableEntity, TableClient } from "@azure/data-tables";
import {
TestProxyHttpClient,
recorderHttpPolicy,
RecorderStartOptions
} from "@azure-tools/test-recorder-new";
import { TestProxyHttpClient, RecorderStartOptions } from "@azure-tools/test-recorder-new";
import { createSimpleEntity } from "./utils/utils";
import { SanitizerOptions } from "@azure-tools/test-recorder-new";

Expand Down Expand Up @@ -51,7 +47,7 @@ describe("Core V2 tests", () => {
env.TABLES_SAS_CONNECTION_STRING,
recorder.variables["table-name"]
);
client.pipeline.addPolicy(recorderHttpPolicy(recorder));
recorder.configureClient(client);
await client.createTable();
const simpleEntity: TableEntity = createSimpleEntity();
await client.createEntity(simpleEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {
RecorderStartOptions,
NoOpCredential,
recorderHttpPolicy,
TestProxyHttpClient
} from "@azure-tools/test-recorder-new";
import { env, isPlaybackMode } from "@azure-tools/test-recorder";
Expand Down Expand Up @@ -55,7 +54,7 @@ describe(`NoOp credential with Tables`, () => {
}
const tableName = recorder.variables["table-name"];
const client = new TableServiceClient(env.TABLES_URL, credential);
client.pipeline.addPolicy(recorderHttpPolicy(recorder));
recorder.configureClient(client);
await client.createTable(tableName);
await client.deleteTable(tableName);
});
Expand Down