Skip to content

Commit 4a31659

Browse files
update testcase
1 parent f1e683e commit 4a31659

File tree

2 files changed

+66
-27
lines changed

2 files changed

+66
-27
lines changed

test/keyvault.test.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ describe("key vault reference", function () {
4040
});
4141

4242
it("require key vault options to resolve reference", async () => {
43-
return expect(load(createMockedConnectionString())).eventually.rejectedWith("Failed to process the Key Vault reference because Key Vault options are not configured.");
43+
try {
44+
await load(createMockedConnectionString());
45+
} catch (error) {
46+
expect(error.message).eq("Failed to load.");
47+
expect(error.cause.message).eq("Failed to process the Key Vault reference because Key Vault options are not configured.");
48+
return;
49+
}
50+
// we should never reach here, load should throw an error
51+
throw new Error("Expected load to throw.");
4452
});
4553

4654
it("should resolve key vault reference with credential", async () => {
@@ -89,14 +97,21 @@ describe("key vault reference", function () {
8997
});
9098

9199
it("should throw error when secret clients not provided for all key vault references", async () => {
92-
const loadKeyVaultPromise = load(createMockedConnectionString(), {
93-
keyVaultOptions: {
94-
secretClients: [
95-
new SecretClient("https://fake-vault-name.vault.azure.net", createMockedTokenCredential()),
96-
]
97-
}
98-
});
99-
return expect(loadKeyVaultPromise).eventually.rejectedWith("Failed to process the key vault reference. No key vault secret client, credential or secret resolver callback is available to resolve the secret.");
100+
try {
101+
await load(createMockedConnectionString(), {
102+
keyVaultOptions: {
103+
secretClients: [
104+
new SecretClient("https://fake-vault-name.vault.azure.net", createMockedTokenCredential()),
105+
]
106+
}
107+
});
108+
} catch (error) {
109+
expect(error.message).eq("Failed to load.");
110+
expect(error.cause.message).eq("Failed to process the key vault reference. No key vault secret client, credential or secret resolver callback is available to resolve the secret.");
111+
return;
112+
}
113+
// we should never reach here, load should throw an error
114+
throw new Error("Expected load to throw.");
100115
});
101116

102117
it("should fallback to use default credential when corresponding secret client not provided", async () => {

test/startup.test.ts

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ describe("startup", function () {
4343
[[{key: "TestKey", value: "TestValue"}].map(createMockedKeyValue)],
4444
failForAllAttempts);
4545

46-
await expect(load(createMockedConnectionString(), {
47-
startupOptions: {
48-
timeoutInMs: 5_000
49-
}
50-
})).to.be.rejectedWith("Load operation timed out.");
51-
expect(attempt).eq(1);
46+
try {
47+
await load(createMockedConnectionString(), {
48+
startupOptions: {
49+
timeoutInMs: 5_000
50+
}
51+
});
52+
} catch (error) {
53+
expect(error.message).eq("Failed to load.");
54+
expect(error.cause.message).eq("Load operation timed out.");
55+
expect(attempt).eq(1);
56+
return;
57+
}
58+
// we should never reach here, load should throw an error
59+
throw new Error("Expected load to throw.");
5260
});
5361

5462
it("should not retry on non-retriable TypeError", async () => {
@@ -61,12 +69,20 @@ describe("startup", function () {
6169
[[{key: "TestKey", value: "TestValue"}].map(createMockedKeyValue)],
6270
failForAllAttempts);
6371

64-
await expect(load(createMockedConnectionString(), {
65-
startupOptions: {
66-
timeoutInMs: 10_000
67-
}
68-
})).to.be.rejectedWith("Non-retriable Test Error");
69-
expect(attempt).eq(1);
72+
try {
73+
await load(createMockedConnectionString(), {
74+
startupOptions: {
75+
timeoutInMs: 10_000
76+
}
77+
});
78+
} catch (error) {
79+
expect(error.message).eq("Failed to load.");
80+
expect(error.cause.message).eq("Non-retriable Test Error");
81+
expect(attempt).eq(1);
82+
return;
83+
}
84+
// we should never reach here, load should throw an error
85+
throw new Error("Expected load to throw.");
7086
});
7187

7288
it("should not retry on non-retriable RangeError", async () => {
@@ -79,11 +95,19 @@ describe("startup", function () {
7995
[[{key: "TestKey", value: "TestValue"}].map(createMockedKeyValue)],
8096
failForAllAttempts);
8197

82-
await expect(load(createMockedConnectionString(), {
83-
startupOptions: {
84-
timeoutInMs: 10_000
85-
}
86-
})).to.be.rejectedWith("Non-retriable Test Error");
87-
expect(attempt).eq(1);
98+
try {
99+
await load(createMockedConnectionString(), {
100+
startupOptions: {
101+
timeoutInMs: 10_000
102+
}
103+
});
104+
} catch (error) {
105+
expect(error.message).eq("Failed to load.");
106+
expect(error.cause.message).eq("Non-retriable Test Error");
107+
expect(attempt).eq(1);
108+
return;
109+
}
110+
// we should never reach here, load should throw an error
111+
throw new Error("Expected load to throw.");
88112
});
89113
});

0 commit comments

Comments
 (0)