app

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 41 Imported by: 0

Documentation

Overview

nolint

nolint

nolint

Index

Constants

View Source
const (
	NoRunMessage = "nothing to run"

	FormatYAML = "yaml"

	FormatText = "text"
)

Variables

View Source
var ImportPath string

ImportPath is the import path of the testing binary, set by the generated main function.

Functions

func DefaultSetOpts added in v0.13.0

func DefaultSetOpts(opts map[string]cty.Value, pendingOptions []PendingOption) error

func GenerateShim

func GenerateShim(variantBin, dir string) error

func Getenv

func Getenv(name string)

Getenv calls Logger().Getenv, if a logger has been set.

func IsExpressionEmpty

func IsExpressionEmpty(ex hcl2.Expression) bool

func MakeQuestions added in v0.13.0

func MakeQuestions(pendingOptions []PendingOption) ([]*survey.Question, map[string]survey.Transformer, error)

func Open

func Open(name string)

Open calls Logger().Open, if a logger has been set.

func SetLogger

func SetLogger(impl Interface)

SetLogger sets the test logger implementation for the current process. It must be called only once, at process startup.

func SetOptsFromMap added in v0.13.0

func SetOptsFromMap(transformers map[string]survey.Transformer, opts map[string]cty.Value, res map[string]interface{}) error

func Stat

func Stat(name string)

Stat calls Logger().Stat, if a logger has been set.

Types

type App

type App struct {
	BinName string

	Files     map[string]*hcl2.File
	Config    *HCL2Config
	JobByName map[string]JobSpec

	Stdout, Stderr io.Writer

	Trace string
}

func New

func New(dir string) (*App, error)

func NewFromFile

func NewFromFile(file string) (*App, error)

func NewFromSources

func NewFromSources(srcs map[string][]byte) (*App, error)

func (*App) ExitWithError

func (app *App) ExitWithError(err error)

func (*App) ExportBinary

func (app *App) ExportBinary(srcDir, dstFile string) error

func (*App) ExportGo

func (app *App) ExportGo(srcDir, dstDir string) error

func (*App) ExportShim

func (app *App) ExportShim(srcDir, dstDir string) error

func (*App) Job

func (app *App) Job(l *EventLogger, cmd string, args map[string]interface{}, opts map[string]interface{}, f SetOptsFunc) (func() (*Result, error), error)

func (*App) PrintDiags added in v0.21.0

func (app *App) PrintDiags(err error)

func (*App) PrintError

func (app *App) PrintError(err error)

func (*App) Run

func (app *App) Run(cmd string, args map[string]interface{}, opts map[string]interface{}, fs ...SetOptsFunc) (*Result, error)

func (*App) RunTests

func (app *App) RunTests(pat string) (*Result, error)

func (*App) WriteDiags

func (app *App) WriteDiags(diagnostics hcl2.Diagnostics)

type Assert

type Assert struct {
	Name string `hcl:"name,label"`

	Condition hcl2.Expression `hcl:"condition,attr"`
}

type Case

type Case struct {
	Name string `hcl:"name,label"`

	Args map[string]hcl2.Expression `hcl:",remain"`
}

type Collect

type Collect struct {
	Condition hcl2.Expression `hcl:"condition,attr"`
	Format    hcl2.Expression `hcl:"format,attr"`
}

type Command added in v0.19.0

type Command struct {
	Name string
	Args []string
	Env  map[string]string
	Dir  string

	Interactive bool
}

type Config

type Config struct {
	Name string `hcl:"name,label"`

	Sources []Source `hcl:"source,block"`
}

type DependsOn added in v0.20.0

type DependsOn struct {
	Name string `hcl:"name,label"`

	Items hcl2.Expression `hcl:"items,attr"`
	Args  hcl2.Expression `hcl:"args,attr"`
}

type DynamicRun added in v0.22.0

type DynamicRun struct {
	Job  string          `hcl:"job,attr"`
	Args hcl2.Expression `hcl:"with,attr"`
}

type EnvSource

type EnvSource struct {
	Name string `hcl:"name,label"`
}

type Event

type Event struct {
	Type string
	Time time.Time
	Run  *RunEvent
	Exec *ExecEvent
}

type EventLogger

type EventLogger struct {
	Command    string
	Args, Opts map[string]interface{}

	Stream string

	Stderr io.Writer

	Events []Event
	// contains filtered or unexported fields
}

func NewEventLogger

func NewEventLogger(cmd string, args map[string]interface{}, opts map[string]interface{}) *EventLogger

func (*EventLogger) LogExec

func (l *EventLogger) LogExec(cmd string, args []string) error

func (*EventLogger) LogRun

func (l *EventLogger) LogRun(job string, args map[string]interface{}) error

func (*EventLogger) Register

func (l *EventLogger) Register(logCollector LogCollector) func() error

type Exec

type Exec struct {
	Command hcl2.Expression `hcl:"command,attr"`

	Args hcl2.Expression `hcl:"args,attr"`
	Env  hcl2.Expression `hcl:"env,attr"`
	Dir  hcl2.Expression `hcl:"dir,attr"`

	Interactive *bool `hcl:"interactive,attr"`
}

type ExecEvent

type ExecEvent struct {
	Command string
	Args    []string
}

type Forward

type Forward struct {
	Run *StaticRun `hcl:"run,block"`
}

type HCL2Config

type HCL2Config struct {
	Jobs    []JobSpec `hcl:"job,block"`
	Tests   []Test    `hcl:"test,block"`
	JobSpec `hcl:",remain"`
}

type Interface

type Interface interface {
	Getenv(key string)
	Stat(file string)
	Open(file string)
	Chdir(dir string)
}

Interface is the interface required of test loggers. The os package will invoke the interface's methods to indicate that it is inspecting the given environment variables or files. Multiple goroutines may call these methods simultaneously.

func Logger

func Logger() Interface

Logger returns the current test logger implementation. It returns nil if there is no logger.

type JobSpec

type JobSpec struct {
	//Type string `hcl:"type,label"`
	Name string `hcl:"name,label"`

	Version *string `hcl:"version,attr"`

	Module hcl2.Expression `hcl:"module,attr"`

	Description *string      `hcl:"description,attr"`
	Parameters  []Parameter  `hcl:"parameter,block"`
	Options     []OptionSpec `hcl:"option,block"`
	Configs     []Config     `hcl:"config,block"`
	Secrets     []Config     `hcl:"secret,block"`
	Variables   []Variable   `hcl:"variable,block"`

	Concurrency hcl2.Expression `hcl:"concurrency,attr"`

	SourceLocator hcl2.Expression `hcl:"__source_locator,attr"`

	Deps   []DependsOn     `hcl:"depends_on,block"`
	Exec   *Exec           `hcl:"exec,block"`
	Assert []Assert        `hcl:"assert,block"`
	Fail   hcl2.Expression `hcl:"fail,attr"`
	Import *string         `hcl:"import,attr"`

	// Private hides the job from `variant run -h` when set to true
	Private *bool `hcl:"private,attr"`

	Log *LogSpec `hcl:"log,block"`

	Steps []Step `hcl:"step,block"`

	Body hcl2.Body `hcl:",remain"`
}

type LazyDynamicRun added in v0.22.0

type LazyDynamicRun struct {
	Run DynamicRun `hcl:"run,block"`
}

type LazyStaticRun added in v0.22.0

type LazyStaticRun struct {
	Run StaticRun `hcl:"run,block"`
}

type Log

type Log struct {
	File string
}

type LogCollector

type LogCollector struct {
	FilePath  string
	CollectFn func(Event) (*string, bool, error)
	ForwardFn func(log Log) error
	// contains filtered or unexported fields
}

func (*LogCollector) Collect

func (c *LogCollector) Collect(evt Event) (*string, error)

type LogSpec

type LogSpec struct {
	File     hcl2.Expression `hcl:"file,attr"`
	Stream   hcl2.Expression `hcl:"stream,attr"`
	Collects []Collect       `hcl:"collect,block"`
	Forwards []Forward       `hcl:"forward,block"`
}

type OptionSpec

type OptionSpec struct {
	Name string `hcl:"name,label"`

	Type        hcl2.Expression `hcl:"type,attr"`
	Default     hcl2.Expression `hcl:"default,attr"`
	Description *string         `hcl:"description,attr"`
	Short       *string         `hcl:"short,attr"`
}

type Parameter

type Parameter struct {
	Name string `hcl:"name,label"`

	Type    hcl2.Expression `hcl:"type,attr"`
	Default hcl2.Expression `hcl:"default,attr"`
	Envs    []EnvSource     `hcl:"env,block"`

	Description *string `hcl:"description,attr"`
}

type PendingOption

type PendingOption struct {
	Spec OptionSpec
	Type cty.Type
}

type Result

type Result struct {
	Stdout     string
	Stderr     string
	Noop       bool
	ExitStatus int
}

type RunEvent

type RunEvent struct {
	Job  string
	Args map[string]interface{}
}

type SetOptsFunc added in v0.13.0

type SetOptsFunc func(opts map[string]cty.Value, pendingOptions []PendingOption) error

type Source

type Source struct {
	Type string `hcl:"type,label"`

	Body hcl2.Body `hcl:",remain"`
}

type SourceFile

type SourceFile struct {
	Path    string  `hcl:"path,attr"`
	Default *string `hcl:"default,attr"`
	Key     *string `hcl:"key,attr"`
}

type SourceJob

type SourceJob struct {
	Name string `hcl:"name,attr"`
	// This results in "no cty.Type for hcl.Expression" error
	//Arguments map[string]hcl2.Expression `hcl:"args,attr"`
	Args   hcl2.Expression `hcl:"args,attr"`
	Format *string         `hcl:"format,attr"`
	Key    *string         `hcl:"key,attr"`
}

type StaticRun added in v0.22.0

type StaticRun struct {
	Name string `hcl:"name,label"`

	Args map[string]hcl2.Expression `hcl:",remain"`
}

type Step

type Step struct {
	Name string `hcl:"name,label"`

	Run StaticRun `hcl:"run,block"`

	Needs *[]string `hcl:"need,attr"`
}

type Test

type Test struct {
	Name string `hcl:"name,label"`

	Variables []Variable `hcl:"variable,block"`
	Cases     []Case     `hcl:"case,block"`
	Run       StaticRun  `hcl:"run,block"`
	Assert    []Assert   `hcl:"assert,block"`

	SourceLocator hcl2.Expression `hcl:"__source_locator,attr"`
}

type TestDeps

type TestDeps struct{}

TestDeps is an implementation of the testing.testDeps interface, suitable for passing to testing.MainStart.

func (TestDeps) ImportPath

func (TestDeps) ImportPath() string

func (TestDeps) MatchString

func (TestDeps) MatchString(pat, str string) (result bool, err error)

func (TestDeps) StartCPUProfile

func (TestDeps) StartCPUProfile(w io.Writer) error

func (TestDeps) StartTestLog

func (TestDeps) StartTestLog(w io.Writer)

func (TestDeps) StopCPUProfile

func (TestDeps) StopCPUProfile()

func (TestDeps) StopTestLog

func (TestDeps) StopTestLog() error

func (TestDeps) WriteProfileTo

func (TestDeps) WriteProfileTo(name string, w io.Writer, debug int) error

type Variable

type Variable struct {
	Name string `hcl:"name,label"`

	Type  hcl2.Expression `hcl:"type,attr"`
	Value hcl2.Expression `hcl:"value,attr"`
}

Jump to

Keyboard shortcuts

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