in internal/engine/engine.go [58:144]
func (e *Engine) TestScenario(scenario *common.Scenario) error {
return fs.UsingDirectory(e.Configuration.WorkingDirectory, func() error {
az.SetCorrelationId(e.Configuration.CorrelationId, scenario.Environment)
stepsToExecute := filterDeletionCommands(scenario.Steps, e.Configuration.DoNotDelete)
initialEnvironmentVariables := lib.GetEnvironmentVariables()
model, err := test.NewTestModeModel(
scenario.Name,
e.Configuration.Subscription,
e.Configuration.Environment,
stepsToExecute,
lib.CopyMap(scenario.Environment),
)
if err != nil {
return err
}
var flags []tea.ProgramOption
if environments.EnvironmentsGithubAction == e.Configuration.Environment {
flags = append(
flags,
tea.WithoutRenderer(),
tea.WithOutput(os.Stdout),
tea.WithInput(os.Stdin),
)
} else {
flags = append(flags, tea.WithAltScreen(), tea.WithMouseCellMotion())
}
common.Program = tea.NewProgram(model, flags...)
var finalModel tea.Model
finalModel, err = common.Program.Run()
// TODO(vmarcella): After testing is complete, we should generate a report.
model, ok := finalModel.(test.TestModeModel)
if !ok {
err = errors.Join(err, fmt.Errorf("failed to cast tea.Model to TestModeModel"))
return err
}
if e.Configuration.ReportFile != "" {
allEnvironmentVariables, envErr := lib.LoadEnvironmentStateFile(
lib.DefaultEnvironmentStateFile,
)
if envErr != nil {
logging.GlobalLogger.Errorf("Failed to load environment state file: %s", err)
err = errors.Join(err, fmt.Errorf("failed to load environment state file: %s", err))
return err
}
variablesDeclaredByScenario := lib.DiffMapsByKey(
allEnvironmentVariables,
initialEnvironmentVariables,
)
report := common.BuildReport(scenario.Name)
err = report.
WithProperties(scenario.Properties).
WithEnvironmentVariables(variablesDeclaredByScenario).
WithError(model.GetFailure()).
WithCodeBlocks(model.GetCodeBlocks()).
WriteToJSONFile(e.Configuration.ReportFile)
if err != nil {
err = errors.Join(err, fmt.Errorf("failed to write report to file: %s", err))
return err
}
model.CommandLines = append(
model.CommandLines,
"Report written to "+e.Configuration.ReportFile,
)
}
fmt.Println(strings.Join(model.CommandLines, "\n"))
err = errors.Join(err, model.GetFailure())
if err != nil {
logging.GlobalLogger.Errorf("Failed to run ie test %s", err)
return err
}
return nil
})
}