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