diff --git a/test/utils/testHelper.ts b/test/utils/testHelper.ts index 6db4bf62..679069c4 100644 --- a/test/utils/testHelper.ts +++ b/test/utils/testHelper.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import * as sinon from "sinon"; -import { AppConfigurationClient } from "@azure/app-configuration"; +import { AppConfigurationClient, ConfigurationSetting } from "@azure/app-configuration"; import { ClientSecretCredential } from "@azure/identity"; import { KeyVaultSecret, SecretClient } from "@azure/keyvault-secrets"; import * as uuid from "uuid"; @@ -11,7 +11,7 @@ const TEST_CLIENT_ID = "00000000-0000-0000-0000-000000000000"; const TEST_TENANT_ID = "00000000-0000-0000-0000-000000000000"; const TEST_CLIENT_SECRET = "0000000000000000000000000000000000000000"; -function mockAppConfigurationClientListConfigurationSettings(kvList: any[]) { +function mockAppConfigurationClientListConfigurationSettings(kvList: ConfigurationSetting[]) { function* testKvSetGnerator(kvs: any[]) { yield* kvs; } @@ -19,9 +19,18 @@ function mockAppConfigurationClientListConfigurationSettings(kvList: any[]) { const keyFilter = listOptions?.keyFilter ?? "*"; const labelFilter = listOptions?.labelFilter ?? "*"; const kvs = kvList.filter(kv => { - const keyMatched = keyFilter.endsWith("*") ? kv.key.startsWith(keyFilter.slice(0, keyFilter.length - 1)) : kv.key === keyFilter; - const labelMatched = labelFilter.endsWith("*") ? kv.label.startsWith(labelFilter.slice(0, labelFilter.length - 1)) - : (labelFilter === "\0" ? kv.label === null : kv.label === labelFilter); // '\0' in labelFilter, null in config setting. + const keyMatched = keyFilter.endsWith("*") ? kv.key.startsWith(keyFilter.slice(0, -1)) : kv.key === keyFilter; + + let labelMatched = false; + if (labelFilter === "*") { + labelMatched = true; + } else if (labelFilter === "\0") { + labelMatched = kv.label === undefined; + } else if (labelFilter.endsWith("*")) { + labelMatched = kv.label !== undefined && kv.label.startsWith(labelFilter.slice(0, -1)); + } else { + labelMatched = kv.label === labelFilter; + } return keyMatched && labelMatched; }) return testKvSetGnerator(kvs) as any; @@ -64,36 +73,33 @@ const createMockedTokenCredential = (tenantId = TEST_TENANT_ID, clientId = TEST_ return new ClientSecretCredential(tenantId, clientId, clientSecret); } -const createMockedKeyVaultReference = (key: string, vaultUri: string) => ({ +const createMockedKeyVaultReference = (key: string, vaultUri: string): ConfigurationSetting => ({ // https://${vaultName}.vault.azure.net/secrets/${secretName} value: `{"uri":"${vaultUri}"}`, key, - label: null, contentType: "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8", - lastModified: "2023-05-09T08:51:11.000Z", + lastModified: new Date(), tags: { }, etag: "SPJSMnJ2ph4BAjftWfdIctV2VIyQxtcIzRbh1oxTBkM", isReadOnly: false, }); -const createMockedJsonKeyValue = (key: string, value: any) => ({ +const createMockedJsonKeyValue = (key: string, value: any): ConfigurationSetting => ({ value: value, key: key, - label: null, contentType: "application/json", - lastModified: "2023-05-04T04:32:56.000Z", + lastModified: new Date(), tags: {}, etag: "GdmsLWq3mFjFodVEXUYRmvFr3l_qRiKAW_KdpFbxZKk", isReadOnly: false }); -const createMockedKeyValue = (props: {[key: string]: any}) => (Object.assign({ +const createMockedKeyValue = (props: {[key: string]: any}): ConfigurationSetting => (Object.assign({ value: "TestValue", key: "TestKey", - label: null, contentType: "", - lastModified: new Date().toISOString(), + lastModified: new Date(), tags: {}, etag: uuid.v4(), isReadOnly: false