context

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MixinOutputsDir represents the directory where mixin output files are written/read
	MixinOutputsDir = "/cnab/app/porter/outputs"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CensoredWriter

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

CensoredWriter is a writer wrapping the provided io.Writer with logic to censor certain values

func NewCensoredWriter

func NewCensoredWriter(writer io.Writer) *CensoredWriter

NewCensoredWriter returns a new CensoredWriter

func (*CensoredWriter) SetSensitiveValues

func (cw *CensoredWriter) SetSensitiveValues(vals []string)

SetSensitiveValues sets values needing masking for an CensoredWriter

func (*CensoredWriter) Write

func (cw *CensoredWriter) Write(b []byte) (int, error)

Write implements io.Writer's Write method, performing necessary auditing while doing so

type CommandBuilder

type CommandBuilder func(name string, arg ...string) *exec.Cmd

func NewTestCommand

func NewTestCommand(c *Context) CommandBuilder

type Context

type Context struct {
	Debug        bool
	DebugPlugins bool

	FileSystem         aferox.Aferox
	In                 io.Reader
	Out                io.Writer
	Err                io.Writer
	NewCommand         CommandBuilder
	PlugInDebugContext *PluginDebugContext
	// contains filtered or unexported fields
}

func New

func New() *Context

New creates a new context in the specified directory.

func (*Context) Chdir added in v0.31.0

func (c *Context) Chdir(dir string)

Chdir changes the current working directory to the named directory.

func (*Context) Clearenv added in v0.31.0

func (c *Context) Clearenv()

Clearenv deletes all environment variables.

func (*Context) Command added in v0.31.0

func (c *Context) Command(name string, arg ...string) *exec.Cmd

Command creates a new exec.Cmd using the context's current directory.

func (*Context) CopyDirectory

func (c *Context) CopyDirectory(srcDir, destDir string, includeBaseDir bool) error

func (*Context) CopyFile

func (c *Context) CopyFile(src, dest string) error

func (*Context) Environ added in v0.31.0

func (c *Context) Environ() []string

Environ returns a copy of strings representing the environment, in the form "key=value".

func (*Context) EnvironMap added in v0.37.1

func (c *Context) EnvironMap() map[string]string

EnvironMap returns a map of the current environment variables.

func (*Context) ExpandEnv added in v0.31.0

func (c *Context) ExpandEnv(s string) string

ExpandEnv replaces ${var} or $var in the string according to the values of the current environment variables. References to undefined variables are replaced by the empty string.

func (*Context) Getenv added in v0.31.0

func (c *Context) Getenv(key string) string

Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present. To distinguish between an empty value and an unset value, use LookupEnv.

func (*Context) Getwd added in v0.31.0

func (c *Context) Getwd() string

Getwd returns a rooted path name corresponding to the current directory.

func (*Context) IsVerbose

func (c *Context) IsVerbose() bool

func (*Context) LookPath added in v0.31.0

func (c *Context) LookPath(file string) (string, bool)

This is a simplified exec.LookPath that checks if command is accessible given a PATH environment variable.

func (*Context) LookupEnv added in v0.31.0

func (c *Context) LookupEnv(key string) (string, bool)

LookupEnv retrieves the value of the environment variable named by the key. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.

func (*Context) SetSensitiveValues

func (c *Context) SetSensitiveValues(vals []string)

SetSensitiveValues sets the sensitive values needing masking on output/err streams

func (*Context) SetVerbose

func (c *Context) SetVerbose(value bool)

func (*Context) Setenv added in v0.31.0

func (c *Context) Setenv(key string, value string)

Setenv sets the value of the environment variable named by the key. It returns an error, if any.

func (*Context) Unsetenv added in v0.31.0

func (c *Context) Unsetenv(key string)

Unsetenv unsets a single environment variable.

func (*Context) WriteMixinOutputToFile

func (c *Context) WriteMixinOutputToFile(filename string, bytes []byte) error

WriteMixinOutputToFile writes the provided bytes (representing a mixin output) to a file named by the provided filename in Porter's mixin outputs directory

type PluginDebugContext added in v0.29.1

type PluginDebugContext struct {
	RunPlugInInDebugger    string
	PlugInWorkingDirectory string
	DebuggerPort           string
}

func NewPluginDebugContext added in v0.29.1

func NewPluginDebugContext(c *Context) *PluginDebugContext

type TestContext

type TestContext struct {
	*Context

	T *testing.T
	// contains filtered or unexported fields
}

func NewTestContext

func NewTestContext(t *testing.T) *TestContext

NewTestContext initializes a configuration suitable for testing, with the output buffered, and an in-memory file system, using the specified environment variables.

func (*TestContext) AddCleanupDir added in v0.28.0

func (c *TestContext) AddCleanupDir(dir string)

func (*TestContext) AddTestDirectory

func (c *TestContext) AddTestDirectory(srcDir, destDir string, mode ...os.FileMode)

mode is optional and should only be specified once

func (*TestContext) AddTestDriver added in v0.28.0

func (c *TestContext) AddTestDriver(src, name string) string

func (*TestContext) AddTestFile

func (c *TestContext) AddTestFile(src, dest string, mode ...os.FileMode) []byte

mode is optional and only the first one passed is used.

func (*TestContext) AddTestFileContents

func (c *TestContext) AddTestFileContents(file []byte, dest string) error

func (*TestContext) Cleanup added in v0.28.0

func (c *TestContext) Cleanup()

func (*TestContext) ClearOutputs added in v0.28.0

func (c *TestContext) ClearOutputs()

func (*TestContext) FindBinDir

func (c *TestContext) FindBinDir() string

FindBinDir returns the path to the bin directory of the repository where the test is currently running

func (*TestContext) FindRepoRoot added in v0.38.2

func (c *TestContext) FindRepoRoot() string

FindRepoRoot returns the path to the porter repository where the test is currently running

func (*TestContext) GetError

func (c *TestContext) GetError() string

GetError returns all text printed to stderr.

func (*TestContext) GetOutput

func (c *TestContext) GetOutput() string

GetOutput returns all text printed to stdout.

func (*TestContext) GetTestDefinitionDirectory added in v0.31.0

func (c *TestContext) GetTestDefinitionDirectory() string

func (*TestContext) UseFilesystem added in v0.28.0

func (c *TestContext) UseFilesystem() (testDir string, homeDir string)

UseFilesystem has porter's context use the OS filesystem instead of an in-memory filesystem Returns the test directory, and the temp porter home directory.

Jump to

Keyboard shortcuts

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