env

package
v0.2201.8 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Overview

Package env defines a scenario environment.

Index

Constants

This section is empty.

Variables

CmdAttrs is the SysProcAttr that will ensure graceful cleanup (on Linux).

View Source
var ErrEarlyTerm = errors.New("env: sub-process exited early")

ErrEarlyTerm is the error passed over the error channel when a sub-process terminates prior to the Cleanup.

View Source
var (

	// Flags has the configuration flags.
	Flags = flag.NewFlagSet("", flag.ContinueOnError)
)

Functions

This section is empty.

Types

type CleanupFn

type CleanupFn func()

CleanupFn is the cleanup hook function prototype.

type Dir

type Dir struct {
	// contains filtered or unexported fields
}

Dir is a directory for test data and output.

func GetRootDir

func GetRootDir() *Dir

GetRootDir returns the global root Dir instance.

Warning: This is not guaranteed to be valid till after `Dir.Init` is called. Use of this routine from outside `oasis-test-runner/cmd` is strongly discouraged.

func (*Dir) Cleanup

func (d *Dir) Cleanup()

Cleanup cleans up the Dir.

func (*Dir) Init

func (d *Dir) Init(cmd *cobra.Command) error

Init initializes the Dir, creating it iff it does not yet exist.

func (*Dir) NewLogWriter

func (d *Dir) NewLogWriter(name string) (io.WriteCloser, error)

NewLogWriter creates a log file under a Dir with the provided name.

func (*Dir) NewSubDir

func (d *Dir) NewSubDir(subDirName string) (*Dir, error)

NewSubDir creates a new subdirectory under a Dir, and returns the sub-directory's Dir.

func (*Dir) SetNoCleanup

func (d *Dir) SetNoCleanup(v bool)

SetNoCleanup enables/disables the removal of the Dir on Cleanup.

func (*Dir) String

func (d *Dir) String() string

String returns the string representation (path) of the Dir.

type Env

type Env struct {
	// contains filtered or unexported fields
}

Env is a (nested) test environment.

func New

func New(dir *Dir) *Env

New creates a new root test environment.

func (*Env) AddOnCleanup

func (env *Env) AddOnCleanup(fn CleanupFn)

AddOnCleanup adds a cleanup routine to be called during the environment's cleanup. Routines will be called in reverse order that they were registered.

func (*Env) AddTermOnCleanup

func (env *Env) AddTermOnCleanup(cmd *exec.Cmd) chan error

AddTermOnCleanup adds a process that will be terminated during the environment's cleanup, and will return a channel that will be closed (after an error is sent if applicable when the process terminates.

Process will be terminated in the reverse order that they were registered.

Processes are torn down *BEFORE* the on-cleanup hooks are run.

func (*Env) Cleanup

func (env *Env) Cleanup()

Cleanup cleans up all of the environment's children, followed by the environment.

Note: Unless the env is a root (top-level) environment, the directory will not be cleaned up.

func (*Env) CurrentDir

func (env *Env) CurrentDir() *Dir

CurrentDir returns the test environment's Dir.

func (*Env) Dir

func (env *Env) Dir() string

Dir returns the path to this test environment's data directory.

func (*Env) Name

func (env *Env) Name() string

Name returns the environment name.

func (*Env) NewChild

func (env *Env) NewChild(childName string, scInfo *ScenarioInstanceInfo) (*Env, error)

NewChild returns a new child test environment.

func (*Env) NewSubDir

func (env *Env) NewSubDir(subDirName string) (*Dir, error)

NewSubDir creates a new subdirectory under the test environment.

func (*Env) ScenarioInfo

func (env *Env) ScenarioInfo() *ScenarioInstanceInfo

ScenarioInfo returns the scenario instance information.

func (*Env) WriteScenarioInfo

func (env *Env) WriteScenarioInfo() error

WriteScenarioInfo dumps scenario instance parameter set to scenario_info.json file for debugging afterwards.

type ParameterFlagSet

type ParameterFlagSet struct {
	flag.FlagSet
	// contains filtered or unexported fields
}

ParameterFlagSet is a wrapper for flag.FlagSet to produce nicer JSON output.

func NewParameterFlagSet

func NewParameterFlagSet(name string, eh flag.ErrorHandling) *ParameterFlagSet

NewParameterFlagSet returns new instance of ParameterFlagSet.

func (*ParameterFlagSet) Clone

func (pfs *ParameterFlagSet) Clone() *ParameterFlagSet

Clone clones the parameter flagset.

This function is usually called when cloning scenarios where we also want to clone existing parameter values.

func (*ParameterFlagSet) MarshalJSON

func (pfs *ParameterFlagSet) MarshalJSON() ([]byte, error)

MarshalJSON outputs ParameterFlagSet as an ordinary JSON map.

type ScenarioInstanceInfo

type ScenarioInstanceInfo struct {
	// Scenario is the name of the scenario.
	Scenario string `json:"scenario"`

	// Instance is the name of the scenario instance (e.g. oasis-test-runner123456).
	Instance string `json:"instance"`

	// ParameterSet is the parameter set the scenario was run with.
	ParameterSet *ParameterFlagSet `json:"parameter_set"`

	// Run is the number of the run.
	Run int `json:"run"`
}

ScenarioInstanceInfo contains information of the current scenario run.

Jump to

Keyboard shortcuts

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