Skip to content

Assert error messages and increase timeout for tests #48

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

Merged
merged 1 commit into from
Feb 10, 2024
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
2 changes: 1 addition & 1 deletion src/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function load(
endpoint = new URL(endpoint);
} catch (error) {
if (error.code === "ERR_INVALID_URL") {
throw new Error("Invalid Endpoint URL.", { cause: error });
throw new Error("Invalid endpoint URL.", { cause: error });
} else {
throw error;
}
Expand Down
6 changes: 4 additions & 2 deletions test/keyvault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function mockNewlyCreatedKeyVaultSecretClients() {
mockSecretClientGetSecret(mockedData.map(([_key, secretUri, value]) => [secretUri, value]));
}
describe("key vault reference", function () {
this.timeout(10000);

beforeEach(() => {
mockAppConfigurationClient();
mockNewlyCreatedKeyVaultSecretClients();
Expand All @@ -37,7 +39,7 @@ describe("key vault reference", function () {
});

it("require key vault options to resolve reference", async () => {
expect(load(createMockedConnectionString())).eventually.rejected;
return expect(load(createMockedConnectionString())).eventually.rejectedWith("Configure keyVaultOptions to resolve Key Vault Reference(s).");
});

it("should resolve key vault reference with credential", async () => {
Expand Down Expand Up @@ -93,7 +95,7 @@ describe("key vault reference", function () {
]
}
});
expect(loadKeyVaultPromise).eventually.rejected;
return expect(loadKeyVaultPromise).eventually.rejectedWith("No key vault credential or secret resolver callback configured, and no matching secret client could be found.");
});

it("should fallback to use default credential when corresponding secret client not provided", async () => {
Expand Down
15 changes: 10 additions & 5 deletions test/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const mockedKVs = [{
}].map(createMockedKeyValue);

describe("load", function () {
this.timeout(10000);

before(() => {
mockAppConfigurationClientListConfigurationSettings(mockedKVs);
});
Expand Down Expand Up @@ -65,12 +67,12 @@ describe("load", function () {
});

it("should throw error given invalid connection string", async () => {
expect(load("invalid-connection-string")).eventually.rejected;
return expect(load("invalid-connection-string")).eventually.rejectedWith("Invalid connection string.");
});

it("should throw error given invalid endpoint URL", async () => {
const credential = createMockedTokenCredential();
expect(load("invalid-endpoint-url", credential)).eventually.rejected;
return expect(load("invalid-endpoint-url", credential)).eventually.rejectedWith("Invalid endpoint URL.");
});

it("should trim key prefix if applicable", async () => {
Expand Down Expand Up @@ -117,23 +119,26 @@ describe("load", function () {
expect(settings.get("KeyForEmptyValue")).eq("");
});

it("should not support * or , in label filters", async () => {
it("should not support * in label filters", async () => {
const connectionString = createMockedConnectionString();
const loadWithWildcardLabelFilter = load(connectionString, {
selectors: [{
keyFilter: "app.*",
labelFilter: "*"
}]
});
expect(loadWithWildcardLabelFilter).to.eventually.rejected;
return expect(loadWithWildcardLabelFilter).to.eventually.rejectedWith("The characters '*' and ',' are not supported in label filters.");
});

it("should not support , in label filters", async () => {
const connectionString = createMockedConnectionString();
const loadWithMultipleLabelFilter = load(connectionString, {
selectors: [{
keyFilter: "app.*",
labelFilter: "labelA,labelB"
}]
});
expect(loadWithMultipleLabelFilter).to.eventually.rejected;
return expect(loadWithMultipleLabelFilter).to.eventually.rejectedWith("The characters '*' and ',' are not supported in label filters.");
});

it("should override config settings with same key but different label", async () => {
Expand Down