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

[App Config] Fix App Config Tests #31079

Merged
merged 12 commits into from
Sep 17, 2024
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { SyncTokens, parseSyncToken } from "../../../src/internal/synctokenpolicy";
import {
assertThrowsRestError,
Expand Down Expand Up @@ -113,7 +110,7 @@ describe("http request related tests", function () {
// properly extracting and sending the sync token header (which is
// why they appear to not do much of anything meaningful with what
// they send or reply back with).
describe("request/reply tests for sync token headers", () => {
describe.only("request/reply tests for sync token headers", () => {
minhanh-phan marked this conversation as resolved.
Show resolved Hide resolved
let client: AppConfigurationClient;
let syncTokens: SyncTokens;
let scope: nock.Scope;
Expand All @@ -127,11 +124,13 @@ describe("http request related tests", function () {
syncTokens = new SyncTokens();

// Use NoOpCredential for nock tests to avoid interception for credential request
client =
createAppConfigurationClientForTests({
client = new AppConfigurationClient(
"https://example.com",
new NoOpCredential(),
{
syncTokens: syncTokens,
testCredential: new NoOpCredential(),
} as InternalAppConfigurationClientOptions) || this.skip();
} as InternalAppConfigurationClientOptions,
);

nock.recorder.clear();
nock.restore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import chai from "chai";
import { randomUUID } from "@azure/core-util";
import nock from "nock";

describe("Should not retry forever", () => {
describe.only("Should not retry forever", () => {
minhanh-phan marked this conversation as resolved.
Show resolved Hide resolved
let client: AppConfigurationClient;
const connectionString = "Endpoint=https://myappconfig.azconfig.io;Id=key:ai/u/fake;Secret=abcd=";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
ListConfigurationSettingPage,
ListRevisionsPage,
} from "../../../src";
import { Recorder, RecorderStartOptions, env, isPlaybackMode } from "@azure-tools/test-recorder";
import {
Recorder,
RecorderStartOptions,
assertEnvironmentVariable,
isPlaybackMode,
} from "@azure-tools/test-recorder";
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import { RestError } from "@azure/core-rest-pipeline";
import { TokenCredential } from "@azure/identity";
Expand Down Expand Up @@ -50,12 +55,8 @@ export function createAppConfigurationClientForTests(
testCredential?: TokenCredential;
},
): AppConfigurationClient {
const endpoint = env["AZ_CONFIG_ENDPOINT"];
const endpoint = assertEnvironmentVariable("AZ_CONFIG_ENDPOINT");
const credential = options?.testCredential ?? createTestCredential();
if (endpoint == null) {
throw new Error("Invalid value for APPCONFIG_CONNECTION_STRING");
}

return new AppConfigurationClient(endpoint, credential, options);
}

Expand Down Expand Up @@ -209,6 +210,7 @@ export async function assertThrowsRestError(
await testFunction();
assert.fail(`${message}: No error thrown`);
} catch (err: any) {
console.log("running into ", JSON.stringify(err));
if (!(err instanceof Error)) {
throw new Error("Error is not recognized");
}
Expand Down
1 change: 1 addition & 0 deletions sdk/core/core-rest-pipeline/src/nodeHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class NodeHttpClient implements HttpClient {
const req = isInsecure ? http.request(options, resolve) : https.request(options, resolve);

req.once("error", (err: Error & { code?: string }) => {
console.log("Error received", JSON.stringify(err));
reject(
new RestError(err.message, { code: err.code ?? RestError.REQUEST_SEND_ERROR, request }),
);
Expand Down
Loading