protected generateScenarioTestData()

in packages/autorest.gotest/src/generator/scenarioTestGenerator.ts [33:111]


  protected generateScenarioTestData(testDef: TestDefinitionModel): void {
    if (testDef.scope.toLowerCase() === 'resourcegroup') {
      this.context.importManager.add('github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources');
    }

    this.globalVariables = {
      ...testDef.requiredVariablesDefault,
      ...testDef.variables,
    };

    for (const step of testDef.prepareSteps) {
      // inner variable should overwrite outer ones
      this.parentVariables = {
        ...this.globalVariables,
      };
      this.currentVariables = {
        ...step.variables,
      };
      this.genRenderDataForStep(step);
    }
    for (const scenario of <Array<TestScenarioModel>>testDef.scenarios) {
      if (scenario.scenario === undefined) {
        scenario.scenario = scenario.description;
      }
      this.scenarioReferencedVariables = new Set<string>();
      for (const step of scenario.steps) {
        // inner variable should overwrite outer ones
        this.parentVariables = {
          ...this.globalVariables,
          ...scenario.requiredVariablesDefault,
          ...scenario.variables,
        };
        this.currentVariables = {
          ...step.variables,
        };
        this.genRenderDataForStep(step);
      }

      // remove useless variable
      for (const variableName of Object.keys(scenario.variables || {})) {
        if (!this.scenarioReferencedVariables.has(variableName)) {
          delete scenario.variables[variableName];
        }
      }

      // resolve scenario variables
      this.parentVariables = {
        ...this.globalVariables,
      };
      this.currentVariables = {
        ...scenario.requiredVariablesDefault,
        ...scenario.variables,
      };
      scenario['variablesOutput'] = {};
      for (const [key, value] of Object.entries(scenario.variables || {})) {
        scenario['variablesOutput'][key] = this.variableValueToString(key, value);
      }
    }
    for (const step of testDef.cleanUpSteps) {
      // inner variable should overwrite outer ones
      this.parentVariables = {
        ...this.globalVariables,
      };
      this.currentVariables = {
        ...step.variables,
      };
      this.genRenderDataForStep(step);
    }

    // resolve scope variables
    this.parentVariables = {};
    this.currentVariables = {
      ...this.globalVariables,
    };
    testDef['variablesOutput'] = {};
    for (const [key, value] of Object.entries(testDef.variables || {})) {
      testDef['variablesOutput'][key] = this.variableValueToString(key, value, false);
    }
  }