This commit is contained in:
Lei Ni 2022-06-05 01:05:40 +08:00
Родитель da1e545fe2
Коммит 1ad06dd59a
7 изменённых файлов: 504 добавлений и 239 удалений

Просмотреть файл

@ -311,7 +311,6 @@ export class ApiScenarioLoader implements Loader<ScenarioDefinition> {
const scenario: Scenario = {
scenario: rawScenario.scenario ?? `scenario_${ctx.scenarioIndex}`,
description: rawScenario.description ?? "",
shareScope: rawScenario.shareScope ?? true,
steps,
_resolvedSteps: resolvedSteps,
_scenarioDef: scenarioDef,

Просмотреть файл

@ -1,6 +1,5 @@
import { HttpMethods } from "@azure/core-http";
import { JsonLoader } from "../swagger/jsonLoader";
import { getLazyBuilder } from "../util/lazyBuilder";
import { getRandomString } from "../util/utils";
import {
ArmTemplate,
@ -36,7 +35,6 @@ export interface Scope {
prepareSteps: Step[];
cleanUpSteps: Step[];
env: VariableEnv;
armDeployments: ArmDeployment[];
}
export interface ApiScenarioClientRequest {
@ -77,11 +75,46 @@ export class ApiScenarioRunner {
private jsonLoader: JsonLoader;
private client: ApiScenarioRunnerClient;
private env: EnvironmentVariables;
private scopeTracking: { [scopeName: string]: Scope };
private resolveVariables: boolean;
private skipCleanUp: boolean;
private provisionScope = getLazyBuilder("provisioned", async (scope: Scope) => {
public constructor(opts: ApiScenarioRunnerOption) {
this.env = opts.env;
this.client = opts.client;
this.jsonLoader = opts.jsonLoader;
this.resolveVariables = opts.resolveVariables ?? true;
this.skipCleanUp = opts.skipCleanUp ?? false;
}
private async prepareScope(scenario: Scenario): Promise<Scope> {
const scenarioDef = scenario._scenarioDef;
// Variable scope: ScenarioDef <= Scenario <= RuntimeScope <= Step
const scopeEnv = new VariableEnv(
new VariableEnv(new VariableEnv().setBatch(scenarioDef.variables)).setBatch(
scenario.variables
)
).setBatchEnv(this.env);
const scope = {
type: scenarioDef.scope,
prepareSteps: scenarioDef.prepareSteps,
cleanUpSteps: scenarioDef.cleanUpSteps,
env: scopeEnv,
};
if (scope.type !== "ResourceGroup") {
throw new Error(`Scope is not supported yet: ${scope.type}`);
}
if (scope.env.get("resourceGroupName") === undefined) {
const resourceGroupPrefix = scope.env.getString("resourceGroupPrefix") ?? "apiTest-";
scope.env.set("resourceGroupName", {
type: "string",
value: resourceGroupPrefix + getRandomString(),
});
}
await this.client.provisionScope(scope);
if (scope.type === "ResourceGroup") {
await this.client.createResourceGroup(
scope.env.getRequiredString("subscriptionId"),
@ -92,55 +125,7 @@ export class ApiScenarioRunner {
for (const step of scope.prepareSteps) {
await this.executeStep(step, scope);
}
return true;
});
public constructor(opts: ApiScenarioRunnerOption) {
this.env = opts.env;
this.client = opts.client;
this.jsonLoader = opts.jsonLoader;
this.resolveVariables = opts.resolveVariables ?? true;
this.skipCleanUp = opts.skipCleanUp ?? false;
this.scopeTracking = {};
}
private async prepareScope(scenario: Scenario): Promise<Scope> {
const scopeName = scenario.shareScope ? "_defaultScope" : `_randomScope_${getRandomString()}`;
let scope = this.scopeTracking[scopeName];
if (scope === undefined) {
const scenarioDef = scenario._scenarioDef;
// Variable scope: ScenarioDef <= Scenario <= RuntimeScope <= Step
const scopeEnv = new VariableEnv(
new VariableEnv(new VariableEnv().setBatch(scenarioDef.variables)).setBatch(
scenario.variables
)
).setBatchEnv(this.env);
scope = {
type: scenarioDef.scope,
prepareSteps: scenarioDef.prepareSteps,
cleanUpSteps: scenarioDef.cleanUpSteps,
env: scopeEnv,
armDeployments: [],
};
if (scope.type !== "ResourceGroup") {
throw new Error(`Scope is not supported yet: ${scope.type}`);
}
if (scope.env.get("resourceGroupName") === undefined) {
const resourceGroupPrefix = scope.env.getString("resourceGroupPrefix") ?? "apiTest-";
scope.env.set("resourceGroupName", {
type: "string",
value: resourceGroupPrefix + getRandomString(),
});
}
this.scopeTracking[scopeName] = scope;
}
await this.client.provisionScope(scope);
await this.provisionScope(scope);
return scope;
}
@ -251,7 +236,6 @@ export class ApiScenarioRunner {
resourceGroupName,
},
};
scope.armDeployments.push(armDeployment);
if (this.resolveVariables) {
step.armTemplatePayload = env.resolveObjectValues(step.armTemplatePayload);

Просмотреть файл

@ -223,11 +223,6 @@ export const ApiScenarioDefinition: Schema & {
variables: {
$ref: "#/definitions/Variables",
},
shareScope: {
type: "boolean",
description: "Whether to share the scope and prepareSteps with other scenarios",
default: true,
},
steps: {
type: "array",
items: {

Просмотреть файл

@ -276,7 +276,6 @@ export type JsonPatchOp =
export type RawScenario = RawVariableScope & {
scenario?: string;
shareScope?: boolean;
description?: string;
steps: RawStep[];
};

Просмотреть файл

@ -106,7 +106,7 @@ export class PostmanCollectionRunnerClient implements ApiScenarioRunnerClient {
}
}
PostmanHelper.reservedVariables.forEach((variable) => {
PostmanHelper.reservedCollectionVariables.forEach((variable) => {
if (!this.collection.variables.has(variable.key)) {
this.collection.variables.add(new Variable(variable));
}

Просмотреть файл

@ -129,7 +129,7 @@ function generateARMTemplateOutputScript(armTemplate: ArmTemplate): string {
return ret;
}
export const reservedVariables = [
export const reservedCollectionVariables = [
{
key: "subscriptionId",
},

Разница между файлами не показана из-за своего большого размера Загрузить разницу