otto

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2016 License: MPL-2.0 Imports: 29 Imported by: 62

Documentation

Index

Constants

View Source
const TestEnvVar = "OTTO_ACC"

TestEnvVar must be set to a non-empty value for acceptance tests to run.

Variables

View Source
var TestAppTuple = app.Tuple{"test", "test", "test"}

TestAppTuple is a basic app tuple that can be used for testing and has all fields set to "test".

Functions

func Test added in v0.2.0

func Test(t TestT, c TestCase)

Test performs an acceptance test on a backend with the given test case.

Tests are not run unless an environmental variable "TF_ACC" is set to some non-empty value. This is to avoid test cases surprising a user by creating real resources.

Tests will fail unless the verbose flag (`go test -v`, or explicitly the "-test.v" flag) is set. Because some acceptance tests take quite long, we require the verbose flag so users are able to see progress output.

func TestApp

func TestApp(t TestT, tuple app.Tuple, c *CoreConfig) *app.Mock

TestApp adds a mock app with the given tuple to the core config.

func TestAppfile added in v0.2.0

func TestAppfile(t TestT, path string) *appfile.Compiled

TestAppfile returns a compiled appfile for the given path. This uses defaults for detectors and such so it is up to you to use a fairly complete Appfile.

func TestFoundation added in v0.1.2

func TestFoundation(t TestT, tuple foundation.Tuple, c *CoreConfig) *foundation.Mock

TestFoundation adds a mock foundation with the given tuple to the core config.

func TestInfra

func TestInfra(t TestT, n string, c *CoreConfig) *infrastructure.Mock

TestInfra adds a mock infrastructure with the given name to the core config and returns it.

Types

type CompileMetadata added in v0.2.0

type CompileMetadata struct {
	// App is the result of compiling the main application
	App *app.CompileResult `json:"app"`

	// Deps are the results of compiling the dependencies, keyed by their
	// unique Otto ID. If you want the tree structure then use the Appfile
	// itself to search the dependency tree, then the ID of that dep
	// to key into this map.
	AppDeps map[string]*app.CompileResult `json:"app_deps"`

	// Infra is the result of compiling the infrastructure for this application
	Infra *infrastructure.CompileResult `json:"infra"`

	// Foundations is the listing of top-level foundation compilation results.
	Foundations map[string]*foundation.CompileResult `json:"foundations"`
}

CompileMetadata is the stored metadata about a successful compilation.

Failures during compilation result in no metadata at all being stored. This metadata can be used to access various information about the resulting compilation.

type Core

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

Core is the main struct to use to interact with Otto as a library.

func NewCore

func NewCore(c *CoreConfig) (*Core, error)

NewCore creates a new core.

Once this function is called, this CoreConfig should not be used again or modified, since the Core may use parts of it without deep copying.

func TestCore added in v0.2.0

func TestCore(t TestT, config *TestCoreOpts) *Core

TestCore returns a *Core for testing. If TestCoreOpts is nil then this is equivalent to creating a core with TestCoreConfig set.

func (*Core) App added in v0.2.0

func (c *Core) App() (app.App, *app.Context, error)

App returns the app implementation and context for this configured Core.

If App implements io.Closer, it is up to the caller to call Close on it.

func (*Core) Build

func (c *Core) Build() error

Build builds the deployable artifact for the currently compiled Appfile.

func (*Core) Compile

func (c *Core) Compile() error

Compile takes the Appfile and compiles all the resulting data.

func (*Core) Deploy

func (c *Core) Deploy(action string, args []string) error

Deploy deploys the application.

Deploy supports subactions, which can be specified with action and args. Action can be "" to get the default deploy behavior.

func (*Core) Dev

func (c *Core) Dev() error

Dev starts a dev environment for the current application. For destroying and other tasks against the dev environment, use the generic `Execute` method.

func (*Core) Execute

func (c *Core) Execute(opts *ExecuteOpts) error

Execute executes the given task for this Appfile.

func (*Core) Infra

func (c *Core) Infra(action string, args []string) error

Infra manages the infrastructure for this Appfile.

Infra supports subactions, which can be specified with action and args. Infra recognizes two special actions: "" (blank string) and "destroy". The former expects to create or update the complete infrastructure, and the latter will destroy the infrastructure.

func (*Core) Status

func (c *Core) Status() error

Status outputs to the UI the status of all the stages of this application.

type CoreConfig

type CoreConfig struct {
	// DataDir is the directory where local data will be stored that
	// is global to all Otto processes.
	//
	// LocalDir is the directory where data local to this single Appfile
	// will be stored. This isn't necessarilly cleared for compilation.
	//
	// CompiledDir is the directory where compiled data will be written.
	// Each compilation will clear this directory.
	DataDir    string
	LocalDir   string
	CompileDir string

	// Appfile is the appfile that this core will be using for configuration.
	// This must be a compiled Appfile.
	Appfile *appfile.Compiled

	// Directory is the directory where data is stored about this Appfile.
	Directory directory.Backend

	// Apps is the map of available app implementations.
	Apps map[app.Tuple]app.Factory

	// Infrastructures is the map of available infrastructures. The
	// value is a factory that can create the infrastructure impl.
	Infrastructures map[string]infrastructure.Factory

	// Foundations is the map of available foundations. The
	// value is a factory that can create the impl.
	Foundations map[foundation.Tuple]foundation.Factory

	// Ui is the Ui that will be used to communicate with the user.
	Ui ui.Ui
}

CoreConfig is configuration for creating a new core with NewCore.

func TestCoreConfig

func TestCoreConfig(t TestT) *CoreConfig

TestCoreConfig returns a CoreConfig that can be used for testing.

type Error

type Error interface {
	OriginalError() error
	Code() string
}

Error is the interface implemented by many errors within Otto. You can use it to check what the type of an error is via the list of error codes below.

type ExecuteOpts

type ExecuteOpts struct {
	// Task is the task to execute
	Task ExecuteTask

	// Action is a sub-action that a task can take. For example:
	// infrastructures accept "destroy", development environments
	// accept "reload", etc.
	Action string

	// Args are additional arguments to the task
	Args []string
}

ExecuteOpts are the options used for executing generic tasks on the Otto environment.

type ExecuteTask

type ExecuteTask uint

ExecuteTask is an enum of available tasks to execute.

const (
	ExecuteTaskInvalid ExecuteTask = 0
	ExecuteTaskDev
)

func (ExecuteTask) String

func (i ExecuteTask) String() string

type TestCase added in v0.2.0

type TestCase struct {
	// Precheck, if non-nil, will be called once before the test case
	// runs at all. This can be used for some validation prior to the
	// test running.
	PreCheck func()

	// Core is the core to use for testing. The Test* methods such
	// as TestCoreConfig should be used to create the test core.
	Core *Core

	// Unit, if set to true, won't require the OTTO_ACC variable to be
	// set and will run as a normal unit test.
	Unit bool

	// Steps are the set of operations that are run for this test case.
	Steps []TestStep

	// Teardown will be called before the test case is over regardless
	// of if the test succeeded or failed. This should return an error
	// in the case that the test can't guarantee all resources were
	// properly cleaned up.
	Teardown TestTeardownFunc
}

TestCase is a single set of tests to run for an app to test the dev experience. See Test for more details on how this operates.

type TestCoreOpts added in v0.2.0

type TestCoreOpts struct {
	// Path is the path to an Appfile to compile
	Path string

	// App to register with the TestAppTuple as a fixed result
	App app.App
}

TestCoreOpts is a specialized struct that is used to create a Core, focused on the most common usage for tests.

type TestStep added in v0.2.0

type TestStep interface {
	// Run is used to run the TestStep. It should return an error if
	// the step failed. If the step fails, then no further steps are
	// called. The Teardown will be called on the TestCase.
	Run(*Core) error
}

TestStep is a single step within a TestCase.

type TestStepSleep added in v0.2.0

type TestStepSleep struct{ Duration time.Duration }

TestStepSleep is a debugging test step that inserts a sleep. This is useful for debugging a failing acceptance test.

func (*TestStepSleep) Run added in v0.2.0

func (t *TestStepSleep) Run(*Core) error

type TestT added in v0.2.0

type TestT interface {
	Error(args ...interface{})
	Fatal(args ...interface{})
	Skip(args ...interface{})
}

TestT is the interface used to handle the test lifecycle of a test.

Users should just use a *testing.T object, which implements this.

type TestTeardownFunc added in v0.2.0

type TestTeardownFunc func(*Core) error

TestTeardownFunc is the callback used for Teardown in TestCase.

Jump to

Keyboard shortcuts

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