scripting

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const (
	TestOutcomeSuccess = "success"
	TestOutcomeFailure = "failure"
	TestOutcomeTimeout = "timeout"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness interface {
	// ID returns a unique ID for the underlying environment. This
	// should match the ID produced by the underlying options
	// implementation that produced this Harness.
	ID() string
	// Setup initializes the environment, and should be safe to
	// call multiple times.
	Setup(context.Context) error
	// Run executes a command (as arguments) with the environment's
	// interpreter.
	Run(context context.Context, args []string) error
	// RunScript takes the body of a script and should write that
	// data to a file and then runs that script directly.
	RunScript(ctx context.Context, script string) error
	// Build will run the environments native build system to
	// generate some kind of build artifact from the scripting
	// environment. Pass a directory in addition to a list of
	// arguments to describe any arguments to the build system.
	// The Build operation returns the path of the build artifact
	// produced by the operation.
	Build(ctx context.Context, dir string, args []string) (string, error)
	// Test provides a way for scripting harness to run tests. The
	// first argument should be a directory, and the successive
	// (optional) arguments should either be arguments to the test
	// runner or names of specific tests to run, depending on the
	// implementation.
	Test(ctx context.Context, dir string, opts ...TestOptions) ([]TestResult, error)
	// Cleanup should remove the files created by the scripting environment.
	Cleanup(context.Context) error
}

Harness provides an interface to execute code in a scripting environment such as a python virtual environment. Implementations should be make it possible to execute either locally or on remote systems.

func NewHarness

func NewHarness(m jasper.Manager, env options.ScriptingHarness) (Harness, error)

NewHarness constructs a scripting harness that wraps the manager. Use this factory function to build new harnesses, which are not cached in the manager (like harnesses constructed directly using Manager.CreateScripting), but are otherwise totally functional.

type HarnessCache

type HarnessCache interface {
	// Create creates a new Harness from the given options and adds it to the
	// cache with the given ID.
	Create(jasper.Manager, options.ScriptingHarness) (Harness, error)
	// Get returns the matching Harness by ID.
	Get(id string) (Harness, error)
	// Add adds a Harness to the cache with the given ID.
	Add(id string, h Harness) error
	// Check returns whether a Harness with the given ID exists in the cache.
	Check(id string) bool
}

HarnessCache provides an internal local cache for scripting environments.

func NewCache

func NewCache() HarnessCache

NewCache constructs a threadsafe HarnessCache instance.

type TestOptions

type TestOptions struct {
	Name    string        `bson:"name" json:"name" yaml:"name"`
	Args    []string      `bson:"args" json:"args" yaml:"args"`
	Pattern string        `bson:"pattern" json:"pattern" yaml:"pattern"`
	Timeout time.Duration `bson:"timeout" json:"timeout" yaml:"timeout"`
	Count   int           `bson:"count" json:"count" yaml:"count"`
}

TestOptions describe settings that modify how tests are executed.

type TestOutcome

type TestOutcome string

TestOutcome reflects the task status.

type TestResult

type TestResult struct {
	Name     string        `bson:"name" json:"name" yaml:"name"`
	StartAt  time.Time     `bson:"start_at" json:"start_at" yaml:"start_at"`
	Duration time.Duration `bson:"duration" json:"duration" yaml:"duration"`
	Outcome  TestOutcome   `bson:"outcome" json:"outcome" yaml:"outcome"`
}

TestResults capture the data about a specific test run.

Jump to

Keyboard shortcuts

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