Skip to content

Commit

Permalink
[KeyVault] - Enable multi-version tests for KV certificates (#19923)
Browse files Browse the repository at this point in the history
Added support for multi-version testing for keyvault-certificates

Resolved #17890
  • Loading branch information
sadasant committed Jan 20, 2022
1 parent 08cb50f commit 93ee7db
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-certificates/package.json
Expand Up @@ -50,7 +50,7 @@
"clean": "rimraf dist-esm dist-test types *.tgz *.log samples/typescript/dist",
"execute:samples": "dev-tool samples run samples-dev",
"extract-api": "tsc -p . && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"samples/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"samples-dev/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"generate:client": "autorest --typescript swagger/README.md",
"integration-test:browser": "karma start --single-run",
"integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 350000 --full-trace \"dist-esm/**/*.spec.js\"",
Expand Down
20 changes: 20 additions & 0 deletions sdk/keyvault/keyvault-certificates/platform-matrix.json
@@ -0,0 +1,20 @@
{
"include": [
{
"Agent": {
"ubuntu-20.04": {
"OSVmImage": "MMSUbuntu20.04",
"Pool": "azsdk-pool-mms-ubuntu-2004-general"
}
},
"TestType": "node",
"NodeTestVersion": "16.x",
"ServiceVersion": ["7.0", "7.1", "7.2"]
}
],
"displayNames": {
"7.0": "service_version_7_0",
"7.1": "service_version_7_1",
"7.2": "service_version_7_2"
}
}
Expand Up @@ -5,6 +5,7 @@ import { assert } from "chai";
import { Context } from "mocha";
import { createSandbox } from "sinon";
import { env, Recorder } from "@azure-tools/test-recorder";
import { getServiceVersion } from "../utils/utils.common";

import {
AuthenticationChallengeCache,
Expand Down Expand Up @@ -37,7 +38,7 @@ describe("Challenge based authentication tests", () => {
};

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
3 changes: 2 additions & 1 deletion sdk/keyvault/keyvault-certificates/test/public/CRUD.spec.ts
Expand Up @@ -18,6 +18,7 @@ import { CertificateClient } from "../../src";
import { assertThrowsAbortError } from "../utils/utils.common";
import { testPollerProperties } from "../utils/recorderUtils";
import { authenticate } from "../utils/testAuthentication";
import { getServiceVersion } from "../utils/utils.common";
import TestClient from "../utils/testClient";

describe("Certificates client - create, read, update and delete", () => {
Expand All @@ -36,7 +37,7 @@ describe("Certificates client - create, read, update and delete", () => {
};

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
suffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
3 changes: 2 additions & 1 deletion sdk/keyvault/keyvault-certificates/test/public/list.spec.ts
Expand Up @@ -11,6 +11,7 @@ import { CertificateClient } from "../../src";
import { assertThrowsAbortError } from "../utils/utils.common";
import { testPollerProperties } from "../utils/recorderUtils";
import { authenticate } from "../utils/testAuthentication";
import { getServiceVersion } from "../utils/utils.common";
import TestClient from "../utils/testClient";

const { expect } = chai;
Expand All @@ -28,7 +29,7 @@ describe("Certificates client - list certificates in various ways", () => {
};

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
suffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
Expand Up @@ -9,6 +9,7 @@ import { env, Recorder } from "@azure-tools/test-recorder";
import { CertificateClient, KeyVaultCertificate, DefaultCertificatePolicy } from "../../src";
import { testPollerProperties } from "../utils/recorderUtils";
import { authenticate } from "../utils/testAuthentication";
import { getServiceVersion } from "../utils/utils.common";
import TestClient from "../utils/testClient";

describe("Certificates client - LRO - create", () => {
Expand All @@ -19,7 +20,7 @@ describe("Certificates client - LRO - create", () => {
let recorder: Recorder;

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
Expand Up @@ -9,6 +9,7 @@ import { env, Recorder } from "@azure-tools/test-recorder";
import { CertificateClient, DeletedCertificate, DefaultCertificatePolicy } from "../../src";
import { testPollerProperties } from "../utils/recorderUtils";
import { authenticate } from "../utils/testAuthentication";
import { getServiceVersion } from "../utils/utils.common";
import TestClient from "../utils/testClient";

describe("Certificates client - lro - delete", () => {
Expand All @@ -19,7 +20,7 @@ describe("Certificates client - lro - delete", () => {
let recorder: Recorder;

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
Expand Up @@ -13,6 +13,7 @@ import {
} from "../../src";
import { testPollerProperties } from "../utils/recorderUtils";
import { authenticate } from "../utils/testAuthentication";
import { getServiceVersion } from "../utils/utils.common";
import TestClient from "../utils/testClient";

describe("Certificates client - LRO - certificate operation", () => {
Expand All @@ -23,7 +24,7 @@ describe("Certificates client - LRO - certificate operation", () => {
let recorder: Recorder;

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
Expand Up @@ -10,6 +10,7 @@ import { CertificateClient, DeletedCertificate, DefaultCertificatePolicy } from
import { assertThrowsAbortError } from "../utils/utils.common";
import { testPollerProperties } from "../utils/recorderUtils";
import { authenticate } from "../utils/testAuthentication";
import { getServiceVersion } from "../utils/utils.common";
import TestClient from "../utils/testClient";

describe("Certificates client - LRO - recoverDelete", () => {
Expand All @@ -20,7 +21,7 @@ describe("Certificates client - LRO - recoverDelete", () => {
let recorder: Recorder;

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
Expand Up @@ -13,6 +13,7 @@ import { CertificateClient } from "../../src";
import { base64ToUint8Array, stringToUint8Array } from "../../src/utils";
import { testPollerProperties } from "../utils/recorderUtils";
import { authenticate } from "../utils/testAuthentication";
import { getServiceVersion } from "../utils/utils.common";
import TestClient from "../utils/testClient";

describe("Certificates client - merge and import certificates", () => {
Expand All @@ -26,7 +27,7 @@ describe("Certificates client - merge and import certificates", () => {
let secretClient: SecretClient;

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
suffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
Expand Up @@ -10,6 +10,7 @@ import { CertificateClient } from "../../src";
import { testPollerProperties } from "../utils/recorderUtils";
import { assertThrowsAbortError } from "../utils/utils.common";
import { authenticate } from "../utils/testAuthentication";
import { getServiceVersion } from "../utils/utils.common";
import TestClient from "../utils/testClient";

describe("Certificates client - restore certificates and recover backups", () => {
Expand All @@ -25,7 +26,7 @@ describe("Certificates client - restore certificates and recover backups", () =>
};

beforeEach(async function (this: Context) {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
suffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
Expand Down
Expand Up @@ -5,10 +5,14 @@ import { ClientSecretCredential } from "@azure/identity";
import { CertificateClient } from "../../src";
import { uniqueString } from "./recorderUtils";
import { env, record, RecorderEnvironmentSetup } from "@azure-tools/test-recorder";
import { getServiceVersion } from "./utils.common";
import TestClient from "./testClient";
import { Context } from "mocha";

export async function authenticate(that: Context): Promise<any> {
export async function authenticate(
that: Context,
serviceVersion: ReturnType<typeof getServiceVersion>
): Promise<any> {
const suffix = uniqueString();
const recorderEnvSetup: RecorderEnvironmentSetup = {
replaceableVariables: {
Expand Down Expand Up @@ -45,7 +49,7 @@ export async function authenticate(that: Context): Promise<any> {
throw new Error("Missing KEYVAULT_URI environment variable.");
}

const client = new CertificateClient(keyVaultUrl, credential);
const client = new CertificateClient(keyVaultUrl, credential, { serviceVersion });
const testClient = new TestClient(client);

return { recorder, client, credential, testClient, suffix, keyVaultUrl };
Expand Down
30 changes: 30 additions & 0 deletions sdk/keyvault/keyvault-certificates/test/utils/utils.common.ts
Expand Up @@ -3,6 +3,8 @@

import { env } from "@azure-tools/test-recorder";
import { assert } from "chai";
import { SupportedVersions, supports, TestFunctionWrapper } from "@azure/test-utils";
import { LATEST_API_VERSION, CertificateClientOptions } from "../../src/certificatesModels";

export function getKeyvaultName(): string {
const keyVaultEnvVarName = "KEYVAULT_NAME";
Expand All @@ -29,3 +31,31 @@ export async function assertThrowsAbortError(cb: () => Promise<any>): Promise<vo
throw new Error("Expected cb to throw an AbortError");
}
}

/**
* The known API versions that we support.
*/
export const serviceVersions = ["7.0", "7.1", "7.2", "7.3-preview"] as const;

/**
* Fetches the service version to test against. This version could be configured as part of CI
* and then passed through the environment in order to support testing prior service versions.
* @returns - The service version to test
*/
export function getServiceVersion(): NonNullable<CertificateClientOptions["serviceVersion"]> {
return env.SERVICE_VERSION || LATEST_API_VERSION;
}

/**
* A convenience wrapper allowing us to limit service versions without using the `versionsToTest` wrapper.
*
* @param supportedVersions - The {@link SupportedVersions} to limit this test against.
* @param serviceVersion - The service version we want to test support for. If omitted we will default to the version returned from {@link getServiceVersion}.
* @returns A Mocha Wrapper which will skip or execute the chained tests depending the currently tested service version and the supported versions.
*/
export function onVersions(
supportedVersions: SupportedVersions,
serviceVersion?: CertificateClientOptions["serviceVersion"]
): TestFunctionWrapper {
return supports(serviceVersion || getServiceVersion(), supportedVersions, serviceVersions);
}
5 changes: 5 additions & 0 deletions sdk/keyvault/keyvault-certificates/tests.yml
Expand Up @@ -6,6 +6,11 @@ stages:
PackageName: "@azure/keyvault-certificates"
ServiceDirectory: keyvault
TimeoutInMinutes: 90
AdditionalMatrixConfigs:
- Name: Keyvault_live_test_base
Path: sdk/keyvault/keyvault-certificates/platform-matrix.json
Selection: sparse
GenerateVMJobs: true
EnvVars:
AZURE_CLIENT_ID: $(aad-azure-sdk-test-client-id)
AZURE_TENANT_ID: $(aad-azure-sdk-test-tenant-id)
Expand Down

0 comments on commit 93ee7db

Please sign in to comment.