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

[Recorder] Make TEST_MODE environment variable value case-insensitive #22118

Merged
merged 2 commits into from
Jun 8, 2022
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
1 change: 1 addition & 0 deletions sdk/test-utils/recorder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Bugs Fixed

- Fixed redirects not being passed to the test proxy in the browser. [#21713](https://github.com/Azure/azure-sdk-for-js/pull/21713)
- The value of the `TEST_MODE` environment variable is no longer case-sensitive. [#22118](https://github.com/Azure/azure-sdk-for-js/pull/22118)

### Other Changes

Expand Down
6 changes: 3 additions & 3 deletions sdk/test-utils/recorder/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export function getTestMode(): TestMode {
if (isPlaybackMode()) {
return "playback";
}
return env.TEST_MODE as "record" | "live";
return env.TEST_MODE?.toLowerCase() as "record" | "live";
}

/** Make a lazy value that can be deferred and only computed once. */
Expand All @@ -327,11 +327,11 @@ export const once = <T>(make: () => T): (() => T) => {
};

export function isRecordMode() {
return env.TEST_MODE === "record";
return env.TEST_MODE?.toLowerCase() === "record";
}

export function isLiveMode() {
return env.TEST_MODE === "live";
return env.TEST_MODE?.toLowerCase() === "live";
}

export function isPlaybackMode() {
Expand Down
29 changes: 28 additions & 1 deletion sdk/test-utils/recorder/test/testProxyClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { expect } from "chai";
import { env, Recorder } from "../src";
import { createRecordingRequest } from "../src/utils/createRecordingRequest";
import { paths } from "../src/utils/paths";
import { getTestMode, isLiveMode, RecorderError, RecordingStateManager } from "../src/utils/utils";
import {
getTestMode,
isLiveMode,
isRecordMode,
RecorderError,
RecordingStateManager,
} from "../src/utils/utils";

const testRedirectedRequest = (
client: Recorder,
Expand Down Expand Up @@ -296,6 +302,27 @@ describe("TestProxyClient functions", () => {
expect(returnedRequest.url).to.equal(initialRequest.url);
});
});

describe("getTestMode", () => {
it("treats the TEST_MODE environment variable case-insensitively", () => {
[
"record",
"RECORD",
"Record",
"playback",
"PLAYBACK",
"Playback",
"live",
"LIVE",
"Live",
].forEach((testMode) => {
env.TEST_MODE = testMode;
expect(getTestMode()).to.equal(testMode.toLowerCase());
expect(isRecordMode()).to.equal(testMode.toLowerCase() === "record");
expect(isLiveMode()).to.equal(testMode.toLowerCase() === "live");
});
});
});
});

describe("State Manager", function () {
Expand Down