Skip to content
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] TestProxyClient takes test context to generate recordings at desired location #17388

Merged
merged 55 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e13ec0d
TestProxyClient takes test context to generate recordings at desired …
HarshaNalluru Aug 31, 2021
40c4a5a
set /workspaces/azure-sdk-for-js/ as entry point
HarshaNalluru Sep 20, 2021
30058f7
use Test as testContext type
HarshaNalluru Sep 20, 2021
5a2509e
update recorder-new tests
HarshaNalluru Sep 20, 2021
70e1bbb
update tests with before and after each
HarshaNalluru Sep 21, 2021
6eb87d1
relativePathCalculator - for browser => done
HarshaNalluru Sep 21, 2021
ccbd14c
create utils folder
HarshaNalluru Sep 21, 2021
47bb18a
export relativeRecordingsPathForBrowser to use in karma.conf
HarshaNalluru Sep 21, 2021
05c00b0
utils folder updates
HarshaNalluru Sep 21, 2021
1968f07
RECORDINGS_RELATIVE_PATH env variable in karma.conf
HarshaNalluru Sep 21, 2021
e950683
node side draft
HarshaNalluru Sep 21, 2021
6cb397c
relativeRecordingsPathForNode
HarshaNalluru Sep 27, 2021
f927df5
findRecordingsFolderPath
HarshaNalluru Sep 27, 2021
25fa7a6
remove console.logs
HarshaNalluru Sep 27, 2021
390cb3f
Update sdk/test-utils/recorder-new/README.md
HarshaNalluru Sep 27, 2021
79c90da
throw new Error(
HarshaNalluru Sep 27, 2021
d3bd3e0
Merge branch 'harshan/recorder/issue/17384' of https://github.com/har…
HarshaNalluru Sep 27, 2021
1475dc2
Update sdk/test-utils/recorder-new/README.md
HarshaNalluru Sep 27, 2021
b49b78e
lock file
HarshaNalluru Sep 27, 2021
5030832
--net=host docs
HarshaNalluru Sep 27, 2021
eeb79cc
sample recordings
HarshaNalluru Sep 27, 2021
b71afda
refactor existing tests
HarshaNalluru Sep 27, 2021
3ce602d
server and tests hitting the server
HarshaNalluru Sep 27, 2021
75e96c2
Merge branch 'harshan/recorder/issue/17384' of https://github.com/har…
HarshaNalluru Sep 27, 2021
c916456
unrelated changes in package.json
HarshaNalluru Sep 27, 2021
fa2e266
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Sep 27, 2021
e110ccf
changelog
HarshaNalluru Sep 27, 2021
a66b3fb
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Sep 27, 2021
344ac2e
lock file
HarshaNalluru Sep 27, 2021
1c9f090
Jeremy's feedbackl
HarshaNalluru Sep 28, 2021
cc4420a
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Sep 30, 2021
3703d8e
lock file
HarshaNalluru Sep 30, 2021
56fa188
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Oct 1, 2021
51cbab0
lock file
HarshaNalluru Oct 1, 2021
91d46ad
Update sdk/test-utils/recorder-new/README.md
HarshaNalluru Oct 1, 2021
28037ec
Update sdk/test-utils/recorder-new/README.md
HarshaNalluru Oct 1, 2021
b863c43
readme
HarshaNalluru Oct 1, 2021
98b8def
Merge branch 'harshan/recorder/issue/17384' of https://github.com/har…
HarshaNalluru Oct 1, 2021
9b2db94
removing the exclamations. 🙂
HarshaNalluru Oct 1, 2021
dace442
address feedback
HarshaNalluru Oct 1, 2021
4f06aff
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Oct 1, 2021
da830bc
clientHttpClient
HarshaNalluru Oct 1, 2021
613f803
sample recordings
HarshaNalluru Oct 2, 2021
9ab9e1b
relativeRecordingsPathForBrowser -> relativeRecordingsPath
HarshaNalluru Oct 2, 2021
c5855cd
massive update to relativeRecordingsPath - which works fine on linux
HarshaNalluru Oct 2, 2021
5fe22e1
RECORDINGS_RELATIVE_PATH in karma.conf
HarshaNalluru Oct 2, 2021
b743285
dist-esm/test/index.spec.js doesn't exist
HarshaNalluru Oct 2, 2021
e942956
lock file
HarshaNalluru Oct 2, 2021
c08f8b1
updates for windows
HarshaNalluru Oct 2, 2021
b1d079c
`--add-host host.docker.internal:host-gateway`
HarshaNalluru Oct 4, 2021
6239815
more comments
HarshaNalluru Oct 4, 2021
e6c6b0a
remove unintended file
HarshaNalluru Oct 4, 2021
912568b
Update sdk/test-utils/recorder-new/CHANGELOG.md
HarshaNalluru Oct 4, 2021
a110c8f
remove sq brackets
HarshaNalluru Oct 4, 2021
53b24cb
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Oct 4, 2021
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
3 changes: 2 additions & 1 deletion sdk/test-utils/recorder-new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"dependencies": {
"@azure-tools/test-recorder": "^1.0.0",
"@azure/core-http": "^2.0.0",
"@azure/core-rest-pipeline": "^1.1.0"
"@azure/core-rest-pipeline": "^1.1.0",
"@azure/test-utils": "^1.0.0"
},
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
Expand Down
5 changes: 3 additions & 2 deletions sdk/test-utils/recorder-new/src/core-v1-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HttpClient, HttpOperationResponse } from "@azure/core-http";
import { DefaultHttpClient, WebResourceLike } from "@azure/core-http";
import { isPlaybackMode, isRecordMode } from "@azure-tools/test-recorder";
import { TestProxyHttpClient } from "./core-v2-recorder";
import { Suite } from "mocha";

/**
* This client manages the recorder life cycle and interacts with the proxy-tool to do the recording,
Expand All @@ -15,8 +16,8 @@ import { TestProxyHttpClient } from "./core-v2-recorder";
*/
export class TestProxyHttpClientCoreV1 extends TestProxyHttpClient {
public httpClientCoreV1: HttpClient;
constructor(sessionFile: string) {
super(sessionFile);
constructor(testContext?: { parent?: Suite | undefined; title: string }) {
super(testContext);
this.httpClientCoreV1 = new DefaultHttpClient();
}

Expand Down
37 changes: 31 additions & 6 deletions sdk/test-utils/recorder-new/src/core-v2-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import {
PipelineResponse,
SendRequest
} from "@azure/core-rest-pipeline";
import { env, isPlaybackMode, isRecordMode } from "@azure-tools/test-recorder";
import {
env,
generateTestRecordingFilePath,
isPlaybackMode,
isRecordMode
} from "@azure-tools/test-recorder";
import { RecorderError, RecordingStateManager } from "./utils";
import { isNode } from "@azure/test-utils";
import { Suite } from "mocha";

const paths = {
playback: "/playback",
Expand All @@ -35,12 +42,30 @@ export class TestProxyHttpClient {
public httpClient: HttpClient;
private stateManager = new RecordingStateManager();
private playback: boolean;
private sessionFile: string;

constructor(private sessionFile: string) {
this.sessionFile = sessionFile;
this.mode = env.TEST_MODE;
this.playback = isPlaybackMode();
this.httpClient = createDefaultHttpClient();
constructor(
private testContext?: {
parent?: Suite | undefined;
title?: string;
}
) {
if (!this.testContext) {
// throw error in record and playback modes saying that file path is undetermined
throw new Error("");
} else {
this.sessionFile =
"sdk/test-utils/testing-recorder-new/recordings/" +
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved
`${generateTestRecordingFilePath(
isNode ? "node" : "browsers",
this.testContext.parent!.fullTitle(),
this.testContext.title!,
"json"
)}`;
this.mode = env.TEST_MODE;
this.playback = isPlaybackMode();
this.httpClient = createDefaultHttpClient();
}
}

/**
Expand Down
36 changes: 20 additions & 16 deletions sdk/test-utils/recorder-new/test/testProxyClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { env } from "@azure-tools/test-recorder";
import { expect } from "chai";
import { TestProxyHttpClient } from "../src";
import { RecorderError, RecordingStateManager } from "../src/utils";
import { Suite } from "mocha";

describe("TestProxyClient functions", () => {
afterEach(() => {
Expand All @@ -21,11 +22,14 @@ describe("TestProxyClient functions", () => {
timeout: 0,
allowInsecureConnection: false
};

const fakeTestContext = {
parent: { fullTitle: () => "" },
title: "dummy_file_name"
} as Suite;
describe("redirectRequest method", () => {
it("request unchanged if not playback or record modes", function() {
env.TEST_MODE = "live";
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
expect(client.redirectRequest(initialRequest)).to.deep.equal(initialRequest);
});

Expand All @@ -36,7 +40,7 @@ describe("TestProxyClient functions", () => {
...initialRequest,
headers: createHttpHeaders({ "x-recording-id": "dummy-recording-id" })
};
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
expect(client.redirectRequest(request)).to.deep.equal(request);
});

Expand All @@ -46,7 +50,7 @@ describe("TestProxyClient functions", () => {
...initialRequest,
headers: createHttpHeaders({})
};
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
client.recordingId = "dummy-recording-id";
expect(client.redirectRequest(request)).to.deep.equal({
...request,
Expand All @@ -64,7 +68,7 @@ describe("TestProxyClient functions", () => {
describe("start method", () => {
it("nothing happens if not playback or record modes", async function() {
env.TEST_MODE = "live";
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
client.httpClient.sendRequest = (): Promise<PipelineResponse> => {
throw new Error("should not have reached here");
};
Expand All @@ -76,7 +80,7 @@ describe("TestProxyClient functions", () => {
`${testMode} mode: ` + "succeeds in playback or record modes and gets a recordingId",
async function() {
env.TEST_MODE = testMode;
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
const recordingId = "dummy-recording-id";
client.httpClient.sendRequest = (): Promise<PipelineResponse> => {
return Promise.resolve({
Expand All @@ -92,7 +96,7 @@ describe("TestProxyClient functions", () => {

it("throws if not received a 200 status code", async function() {
env.TEST_MODE = testMode;
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
const recordingId = "dummy-recording-id";
client.httpClient.sendRequest = (): Promise<PipelineResponse> => {
return Promise.resolve({
Expand All @@ -112,7 +116,7 @@ describe("TestProxyClient functions", () => {

it("throws if not received a recording id upon 200 status code", async function() {
env.TEST_MODE = testMode;
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
client.httpClient.sendRequest = (): Promise<PipelineResponse> => {
return Promise.resolve({
status: 200,
Expand All @@ -136,7 +140,7 @@ describe("TestProxyClient functions", () => {
describe("stop method", () => {
it("nothing happens if not playback or record modes", async function() {
env.TEST_MODE = "live";
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
client.httpClient.sendRequest = (): Promise<PipelineResponse> => {
throw new Error("should not have reached here");
};
Expand All @@ -148,7 +152,7 @@ describe("TestProxyClient functions", () => {
`${testMode} mode: ` + "fails in playback or record modes if no recordingId",
async function() {
env.TEST_MODE = testMode;
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
client.httpClient.sendRequest = (): Promise<PipelineResponse> => {
return Promise.resolve({
status: 200,
Expand All @@ -171,7 +175,7 @@ describe("TestProxyClient functions", () => {

it("throws if status code is not 200", async function() {
env.TEST_MODE = testMode;
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
client.httpClient.sendRequest = (): Promise<PipelineResponse> => {
return Promise.resolve({
status: 401,
Expand All @@ -192,7 +196,7 @@ describe("TestProxyClient functions", () => {

it("succeeds in playback or record modes", async function() {
env.TEST_MODE = testMode;
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
client.httpClient.sendRequest = (): Promise<PipelineResponse> => {
return Promise.resolve({
status: 200,
Expand All @@ -210,7 +214,7 @@ describe("TestProxyClient functions", () => {
describe("modifyRequest method", () => {
it("request unchanged if not playback or record modes", async function() {
env.TEST_MODE = "live";
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
expect(await client.modifyRequest(initialRequest)).to.deep.equal(initialRequest);
});

Expand All @@ -223,7 +227,7 @@ describe("TestProxyClient functions", () => {
...initialRequest,
headers: createHttpHeaders({ "x-recording-id": "dummy-recording-id" })
};
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
expect(await client.modifyRequest(request)).to.deep.equal(request);
}
);
Expand All @@ -234,7 +238,7 @@ describe("TestProxyClient functions", () => {
...initialRequest,
headers: createHttpHeaders({})
};
const client = new TestProxyHttpClient("dummy_file_name");
const client = new TestProxyHttpClient(fakeTestContext);
client.recordingId = "dummy-recording-id";
expect(await client.modifyRequest(request)).to.deep.equal({
...request,
Expand All @@ -251,7 +255,7 @@ describe("TestProxyClient functions", () => {

describe("_createRecordingRequest", () => {
it("_createRecordingRequest adds the recording-file and recording-id headers", () => {
const dummyFileName = "dummy_file_name";
const dummyFileName = fakeTestContext;
const client = new TestProxyHttpClient(dummyFileName);
client.recordingId = "dummy-recording-id";
const returnedRequest = client["_createRecordingRequest"](initialRequest.url);
Expand Down
1 change: 1 addition & 0 deletions sdk/test-utils/recorder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export {
} from "./utils";
export { pluginForIdentitySDK, pluginForClientSecretCredentialTests } from "./utils/msalAuth.node";
export { jsonRecordingFilterFunction } from "./basekarma.conf";
export { generateTestRecordingFilePath } from "./utils/recordingPath";
5 changes: 3 additions & 2 deletions sdk/test-utils/recorder/src/utils/recordingPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export function formatPath(path: string): string {
export function generateTestRecordingFilePath(
platform: "node" | "browsers",
testSuiteTitle: string,
testTitle: string
testTitle: string,
extension?: "js" | "json"
): string {
// File Extension
// nock recordings for node tests - .js extension
// recordings are saved in json format for browser tests - .json extension
const ext = platform === "node" ? "js" : "json";
const ext = !extension ? (platform === "node" ? "js" : "json") : extension;
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved
return `${platform}/${formatPath(testSuiteTitle)}/recording_${formatPath(testTitle)}.${ext}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import { config } from "dotenv";
import { isNode } from "@azure/core-util";
config();

describe("Tests", () => {
it("storage test", async function() {
const file = (isNode ? "node_" : "browser_") + `core_v1_file_path.json`;
const recorder = new TestProxyHttpClientCoreV1(file);
describe("Core V1 tests", () => {
it("storage-queue create queue", async function() {
const recorder = new TestProxyHttpClientCoreV1(this.test);
const options: StoragePipelineOptions = {};
options.httpClient = recorder;
const client = new QueueServiceClient(env.STORAGE_SAS_URL, undefined, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { env } from "@azure-tools/test-recorder";
import { TableEntity, TableClient } from "@azure/data-tables";
import { TestProxyHttpClient, recorderHttpPolicy } from "@azure-tools/test-recorder-new";
import { config } from "dotenv";
import { isNode } from "@azure/core-util";
import { createSimpleEntity } from "./utils/utils";
config();

describe("Tests", () => {
it("tables test", async function() {
const file = (isNode ? "node_" : "browser_") + `core_v2_file_path.json`;
const recorder = new TestProxyHttpClient(file);
describe("Core V2 tests", () => {
it("data-tables create entity", async function() {
const recorder = new TestProxyHttpClient(this.test);
const client = TableClient.fromConnectionString(env.TABLES_SAS_CONNECTION_STRING, "newtable");
client.pipeline.addPolicy(recorderHttpPolicy(recorder));
await recorder.start();
Expand Down