binary

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capture

func Capture(cmd *exec.Cmd) *capture

Capture returns a struct that captures the stdout and stderr for a given exec.Cmd. This provides helpful functions for extracting JSON and errors from stdout and stderr respectively.

Types

type Binary

type Binary interface {
	// ExecuteTest executes a series of commands in order and returns the
	// output of the apply and plan steps, the state, and any additionally
	// requested files.
	ExecuteTest(directory string, includeFiles []string, commands ...Command) (map[string]*files.File, error)

	// Version returns the version of the underlying binary.
	Version() string
}

Binary is an interface that can execute a single equivalence test within a directory using the ExecuteTest method.

We hold this in an interface, so we can mock it for testing purposes.

func New

func New(binaryName string) (Binary, error)

New returns a Binary compatible struct that executes the tests using the selected binary provided in the argument.

type Command

type Command struct {
	// The Name of the command to execute. This field is used for logging when
	// reporting which command might have failed.
	Name string `json:"name"`

	// A list of Arguments to pass to the binary, eg. `init`, `plan`,
	// `show -json`, etc.
	Arguments []string `json:"arguments"`

	// CaptureOutput should be set to true if we want to record the output of
	// this command and compare/copy it into the golden files.
	CaptureOutput bool `json:"capture_output"`

	// OutputFileName is the name of the file that the framework should write
	// the captured output into.
	//
	// This field is ignored if CaptureOutput is false.
	OutputFileName string `json:"output_file_name"`

	// HasJsonOutput tells the framework the output is going to be in JSON
	// format.
	//
	// This means that `IgnoreFields` section of the test specification can be
	// applied to the output of this command. It also provides a better diffing
	// output as JSON is easier to diff and display than raw strings.
	//
	// This field is ignored if CaptureOutput is false.
	HasJsonOutput bool `json:"has_json_output"`

	// StreamsJsonOutput tells the framework the output isn't going to arrive in
	// pure JSON but as a list of structured JSON statements. In this case the
	// framework will strip out any `\n` characters, put the output inside a
	// JSON list: `[`, `]`, and finally append the statements together with a
	// `,` character.
	//
	// This command basically turns the structured output into a JSON list that
	// can be handled by the rest of the framework. An example of this is the
	// output of an apply command: `$binary apply -json`.
	//
	// This field is ignored if CaptureOutput is false or if HasJsonOutput is
	// false.
	StreamsJsonOutput bool `json:"streams_json_output"`
}

Command is a struct that instructs the framework how to execute a custom command. It covers the arguments that should be passed to the binary, and instructs whether the output should be captured and how it should be captured.

type Error

type Error struct {
	Command string
	Go      error
	Binary  error
}

Error wraps an error returned by the executable. There are two errors contained. Go is the error returned by the go exec framework, while Binary is an error made up of the stderr output of the command.

func (Error) Error

func (e Error) Error() string

Error makes our Error struct match the standard Go error interface.

Jump to

Keyboard shortcuts

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