app

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: MIT Imports: 52 Imported by: 0

Documentation

Overview

nolint

nolint

nolint

Index

Constants

View Source
const (
	NoRunMessage = "nothing to run"

	FormatYAML = "yaml"

	FormatText = "text"
)
View Source
const (
	DefaultCacheDir = ".variant2/cache"
)

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 []PendingInput) 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 []PendingInput) ([]*survey.Question, map[string]survey.Transformer, error)

func NewImportFunc added in v0.32.0

func NewImportFunc(importBaseDir string, f func(string) (*App, error)) func(string) (*App, 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]*hcl.File
	Config    *HCL2Config
	JobByName map[string]JobSpec

	Stdout, Stderr io.Writer

	Trace string

	Funcs map[string]function.Function

	JobLocalFuncs map[string]map[string]function.Function
	// contains filtered or unexported fields
}

func New

func New(setup Setup, opts ...Option) (*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(jobCtx *JobContext, l *EventLogger, cmd string, args map[string]interface{}, opts map[string]interface{}, f SetOptsFunc, streamOutput bool) (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 Arg added in v0.23.0

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

type Assert

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

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

type Case

type Case struct {
	SourceLocator hcl.Expression `hcl:"__source_locator,attr"`

	Name string `hcl:"name,label"`

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

type Collect

type Collect struct {
	Condition hcl.Expression `hcl:"condition,attr"`
	Format    hcl.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 []ConfigSource `hcl:"source,block"`
}

type ConfigSource added in v0.36.0

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

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

type DependsOn added in v0.20.0

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

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

type DynamicRun added in v0.22.0

type DynamicRun struct {
	Job       string         `hcl:"job,attr"`
	Args      hcl.Expression `hcl:"with,attr"`
	Condition hcl.Expression `hcl:"condition,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 hcl.Expression `hcl:"command,attr"`

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

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

type ExecEvent

type ExecEvent struct {
	Command string
	Args    []string
}

type Expect added in v0.28.0

type Expect struct {
	// Type must be `exec` for now
	Type string `hcl:"type,label"`

	Command hcl.Expression `hcl:"command,attr"`
	Args    hcl.Expression `hcl:"args,attr"`
	Dir     hcl.Expression `hcl:"dir,attr"`
}

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 Instance added in v0.33.0

type Instance struct {
	Sources map[string][]byte
	Dir     string
}

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 JobContext added in v0.23.0

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

func (JobContext) Ptr added in v0.26.0

func (c JobContext) Ptr() *JobContext

func (*JobContext) WithEvalContext added in v0.26.0

func (c *JobContext) WithEvalContext(evalCtx *hcl2.EvalContext) JobContext

func (*JobContext) WithVariable added in v0.26.0

func (c *JobContext) WithVariable(name string, v cty.Value) JobContext

type JobSpec

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

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

	Module hcl.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 hcl.Expression `hcl:"concurrency,attr"`

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

	Deps    []DependsOn    `hcl:"depends_on,block"`
	Exec    *Exec          `hcl:"exec,block"`
	Assert  []Assert       `hcl:"assert,block"`
	Fail    hcl.Expression `hcl:"fail,attr"`
	Import  *string        `hcl:"import,attr"`
	Imports *[]string      `hcl:"imports,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 hcl.Body `hcl:",remain"`

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

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     hcl.Expression `hcl:"file,attr"`
	Stream   hcl.Expression `hcl:"stream,attr"`
	Collects []Collect      `hcl:"collect,block"`
	Forwards []Forward      `hcl:"forward,block"`
}

type Option added in v0.34.0

type Option func(options *Options)

func WithCacheDir added in v0.34.0

func WithCacheDir(dir string) Option

type OptionSpec

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

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

type Options added in v0.34.0

type Options struct {
	CacheDir string
}

type Parameter

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

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

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

type PendingInput added in v0.23.0

type PendingInput struct {
	Name        string
	Description *string
	Type        cty.Type
}

type Result

type Result struct {
	Stdout    string
	Stderr    string
	Undefined bool
	Skipped   bool
	// Cancelled is set to true when and only when the original command execution has been scheduled concurrently,
	// but was cancelled before it was actually executed.
	Cancelled bool

	// Validated is set to true when and only when the command execution was successfully validated against the mock
	Validated 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 []PendingInput) error

type Setup added in v0.33.0

type Setup func(*Options) (*Instance, error)

func FromDir added in v0.33.0

func FromDir(dir string) Setup

func FromFile added in v0.33.0

func FromFile(path string) Setup

func FromSources added in v0.33.0

func FromSources(srcs map[string][]byte) Setup

type Source

type Source struct {
	ID string `hcl:"id,label"`
	// Kind is the kind of source-controller source kind like "GitRepository" and "Bucket"
	Kind string `hcl:"kind,attr"`
	// Namespace is the K8s namespace of the source-controller source
	Namepsace string `hcl:"namespace,attr"`
	// Name defaults to ID
	Name string `hcl:"name,attr"`
}

type SourceFile

type SourceFile struct {
	Path    *string  `hcl:"path,attr"`
	Paths   []string `hcl:"paths,optional"`
	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   hcl.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]hcl.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 hcl.Expression `hcl:"__source_locator,attr"`

	ExpectedExecs []Expect `hcl:"expect,block"`
}

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) SetPanicOnExit0 added in v0.38.0

func (TestDeps) SetPanicOnExit0(bool)

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  hcl.Expression `hcl:"type,attr"`
	Value hcl.Expression `hcl:"value,attr"`
}

Jump to

Keyboard shortcuts

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