|
2 | 2 | // Licensed under the MIT license. |
3 | 3 |
|
4 | 4 | import * as sinon from "sinon"; |
5 | | -import { AppConfigurationClient, ConfigurationSetting, featureFlagContentType } from "@azure/app-configuration"; |
| 5 | +import { AppConfigurationClient, ConfigurationSetting, featureFlagContentType, secretReferenceContentType } from "@azure/app-configuration"; |
6 | 6 | import { ClientSecretCredential } from "@azure/identity"; |
7 | 7 | import { KeyVaultSecret, SecretClient } from "@azure/keyvault-secrets"; |
8 | 8 | import * as uuid from "uuid"; |
@@ -186,29 +186,29 @@ function mockAppConfigurationClientGetConfigurationSetting(kvList: any[], custom |
186 | 186 | }); |
187 | 187 | } |
188 | 188 |
|
189 | | -function mockAppConfigurationClientGetSnapshot(snapshotName: string, mockedResponse: any, customCallback?: (options) => any) { |
| 189 | +function mockAppConfigurationClientGetSnapshot(snapshotResponses: Map<string, any>, customCallback?: (options) => any) { |
190 | 190 | sinon.stub(AppConfigurationClient.prototype, "getSnapshot").callsFake((name, options) => { |
191 | 191 | if (customCallback) { |
192 | 192 | customCallback(options); |
193 | 193 | } |
194 | 194 |
|
195 | | - if (name === snapshotName) { |
196 | | - return mockedResponse; |
| 195 | + if (snapshotResponses.has(name)) { |
| 196 | + return snapshotResponses.get(name); |
197 | 197 | } else { |
198 | 198 | throw new RestError("", { statusCode: 404 }); |
199 | 199 | } |
200 | 200 | }); |
201 | 201 | } |
202 | 202 |
|
203 | | -function mockAppConfigurationClientListConfigurationSettingsForSnapshot(snapshotName: string, pages: ConfigurationSetting[][], customCallback?: (options) => any) { |
| 203 | +function mockAppConfigurationClientListConfigurationSettingsForSnapshot(snapshotResponses: Map<string, ConfigurationSetting[][]>, customCallback?: (options) => any) { |
204 | 204 | sinon.stub(AppConfigurationClient.prototype, "listConfigurationSettingsForSnapshot").callsFake((name, listOptions) => { |
205 | 205 | if (customCallback) { |
206 | 206 | customCallback(listOptions); |
207 | 207 | } |
208 | 208 |
|
209 | | - if (name === snapshotName) { |
210 | | - const kvs = _filterKVs(pages.flat(), listOptions); |
211 | | - return getMockedIterator(pages, kvs, listOptions); |
| 209 | + if (snapshotResponses.has(name)) { |
| 210 | + const kvs = _filterKVs(snapshotResponses.get(name)!.flat(), listOptions); |
| 211 | + return getMockedIterator(snapshotResponses.get(name)!, kvs, listOptions); |
212 | 212 | } else { |
213 | 213 | throw new RestError("", { statusCode: 404 }); |
214 | 214 | } |
@@ -253,7 +253,7 @@ const createMockedKeyVaultReference = (key: string, vaultUri: string): Configura |
253 | 253 | // https://${vaultName}.vault.azure.net/secrets/${secretName} |
254 | 254 | value: `{"uri":"${vaultUri}"}`, |
255 | 255 | key, |
256 | | - contentType: "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8", |
| 256 | + contentType: secretReferenceContentType, |
257 | 257 | lastModified: new Date(), |
258 | 258 | tags: {}, |
259 | 259 | etag: uuid.v4(), |
@@ -297,6 +297,16 @@ const createMockedFeatureFlag = (name: string, flagProps?: any, props?: any) => |
297 | 297 | isReadOnly: false |
298 | 298 | }, props)); |
299 | 299 |
|
| 300 | +const createMockedSnapshotReference = (key: string, snapshotName: string): ConfigurationSetting => ({ |
| 301 | + value: `{"snapshot_name":"${snapshotName}"}`, |
| 302 | + key, |
| 303 | + contentType: "application/json; profile=\"https://azconfig.io/mime-profiles/snapshot-ref\"; charset=utf-8", |
| 304 | + lastModified: new Date(), |
| 305 | + tags: {}, |
| 306 | + etag: uuid.v4(), |
| 307 | + isReadOnly: false, |
| 308 | +}); |
| 309 | + |
300 | 310 | class HttpRequestHeadersPolicy { |
301 | 311 | headers: any; |
302 | 312 | name: string; |
@@ -329,6 +339,7 @@ export { |
329 | 339 | createMockedJsonKeyValue, |
330 | 340 | createMockedKeyValue, |
331 | 341 | createMockedFeatureFlag, |
| 342 | + createMockedSnapshotReference, |
332 | 343 |
|
333 | 344 | sleepInMs, |
334 | 345 | HttpRequestHeadersPolicy |
|
0 commit comments