common

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Program *tea.Program = nil

TODO: Ideally we won't need a global program variable. We should refactor this in the future such that each tea program is localized to the function that creates it and ExecuteCodeBlockSync doesn't mutate the global program variable.

Functions

func ClearScreen

func ClearScreen() tea.Cmd

clearScreen returns a command that clears the terminal screen and positions the cursor at the top-left corner

func CompareCommandOutputs

func CompareCommandOutputs(
	actualOutput string,
	expectedOutput string,
	expectedSimilarity float64,
	expectedRegex *regexp.Regexp,
	expectedOutputLanguage string,
) (float64, error)

Compares the actual output of a command to the expected output of a command.

func ExecuteCodeBlockAsync

func ExecuteCodeBlockAsync(codeBlock parsers.CodeBlock, env map[string]string) tea.Cmd

Executes a bash command and returns a tea message with the output. This function will be executed asycnhronously.

func ExecuteCodeBlockSync

func ExecuteCodeBlockSync(codeBlock parsers.CodeBlock, env map[string]string) tea.Msg

Executes a bash command syncrhonously. This function will block until the command finishes executing.

func Exit

func Exit(encounteredFailure bool) tea.Cmd

func UpdateAzureStatus

func UpdateAzureStatus(azureStatus environments.AzureDeploymentStatus, environment string) tea.Cmd

Updates the azure status with the current state of the interactive mode model.

Types

type AzureStatusUpdatedMessage

type AzureStatusUpdatedMessage struct{}

Empty struct used to indicate that the azure status has been updated so that we can respond to it within the Update() function.

type ExitMessage

type ExitMessage struct {
	EncounteredFailure bool
}

type FailedCommandMessage

type FailedCommandMessage struct {
	StdOut          string
	StdErr          string
	Error           error
	SimilarityScore float64
}

Emitted when a command has failed to execute.

type Report

type Report struct {
	Name                 string                 `json:"name"`
	Properties           map[string]interface{} `json:"properties"`
	EnvironmentVariables map[string]string      `json:"environmentVariables"`
	Success              bool                   `json:"success"`
	Error                string                 `json:"error"`
	FailedAtStep         int                    `json:"failedAtStep"`
	CodeBlocks           []StatefulCodeBlock    `json:"steps"`
}

func BuildReport

func BuildReport(name string) Report

func (*Report) WithCodeBlocks

func (report *Report) WithCodeBlocks(codeBlocks []StatefulCodeBlock) *Report

func (*Report) WithEnvironmentVariables

func (report *Report) WithEnvironmentVariables(envVars map[string]string) *Report

func (*Report) WithError

func (report *Report) WithError(err error) *Report

func (*Report) WithProperties

func (report *Report) WithProperties(properties map[string]interface{}) *Report

func (*Report) WriteToJSONFile

func (report *Report) WriteToJSONFile(outputPath string) error

TODO(vmarcella): Implement this to write the report to JSON.

type Scenario

type Scenario struct {
	Name        string
	MarkdownAst ast.Node
	Steps       []Step
	Properties  map[string]interface{}
	Environment map[string]string
	Source      []byte
}

Scenarios are the top-level object that represents a scenario to be executed.

func CreateScenarioFromMarkdown

func CreateScenarioFromMarkdown(
	path string,
	languagesToExecute []string,
	environmentVariableOverrides map[string]string,
) (*Scenario, error)

Creates a scenario object from a given markdown file. languagesToExecute is used to filter out code blocks that should not be parsed out of the markdown file.

func (*Scenario) GetSourceAsString added in v0.2.3

func (s *Scenario) GetSourceAsString() string

Get the markdown source for the scenario as a string.

func (*Scenario) ToShellScript

func (s *Scenario) ToShellScript() string

Convert a scenario into a shell script

type StatefulCodeBlock

type StatefulCodeBlock struct {
	CodeBlock       parsers.CodeBlock `json:"codeBlock"`
	CodeBlockNumber int               `json:"codeBlockNumber"`
	Error           error             `json:"error"`
	StdErr          string            `json:"stdErr"`
	StdOut          string            `json:"stdOut"`
	StepName        string            `json:"stepName"`
	StepNumber      int               `json:"stepNumber"`
	Success         bool              `json:"success"`
	SimilarityScore float64           `json:"similarityScore"`
}

State for the codeblock in interactive mode. Used to keep track of the state of each codeblock.

func (StatefulCodeBlock) WasExecuted

func (s StatefulCodeBlock) WasExecuted() bool

Checks if a codeblock was executed by looking at the output, errors, and if success is true.

type Step

type Step struct {
	Name       string
	CodeBlocks []parsers.CodeBlock
}

Individual steps within a scenario.

type SuccessfulCommandMessage

type SuccessfulCommandMessage struct {
	StdOut          string
	StdErr          string
	SimilarityScore float64
}

Emitted when a command has been executed successfully.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL