testutils

package
v0.0.0-...-1fdc273 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExecTaskStreamingBasicCases = []struct {
	Name     string
	Command  string
	Tty      bool
	Stdin    string
	Stdout   interface{}
	Stderr   interface{}
	ExitCode int
}{
	{
		Name:     "notty: basic",
		Command:  "echo hello stdout; echo hello stderr >&2; exit 43",
		Tty:      false,
		Stdout:   "hello stdout\n",
		Stderr:   "hello stderr\n",
		ExitCode: 43,
	},
	{
		Name:     "notty: streaming",
		Command:  "for n in 1 2 3; do echo $n; sleep 1; done",
		Tty:      false,
		Stdout:   "1\n2\n3\n",
		ExitCode: 0,
	},
	{
		Name:     "notty: stty check",
		Command:  "stty size",
		Tty:      false,
		Stderr:   regexp.MustCompile("stty: .?standard input.?: Inappropriate ioctl for device\n"),
		ExitCode: 1,
	},
	{
		Name:     "notty: stdin passing",
		Command:  "echo hello from command; head -n1",
		Tty:      false,
		Stdin:    "hello from stdin\n",
		Stdout:   "hello from command\nhello from stdin\n",
		ExitCode: 0,
	},
	{
		Name:    "notty: children processes",
		Command: "(( sleep 3; echo from background ) & ); echo from main; exec sleep 1",
		Tty:     false,

		Stdout:   "from main\nfrom background\n",
		ExitCode: 0,
	},

	{
		Name:     "tty: basic",
		Command:  "echo hello stdout; echo hello stderr >&2; exit 43",
		Tty:      true,
		Stdout:   "hello stdout\r\nhello stderr\r\n",
		ExitCode: 43,
	},
	{
		Name:     "tty: streaming",
		Command:  "for n in 1 2 3; do echo $n; sleep 1; done",
		Tty:      true,
		Stdout:   "1\r\n2\r\n3\r\n",
		ExitCode: 0,
	},
	{
		Name:     "tty: stty check",
		Command:  "sleep 1; stty size",
		Tty:      true,
		Stdout:   "100 100\r\n",
		ExitCode: 0,
	},
	{
		Name:    "tty: stdin passing",
		Command: "head -n1",
		Tty:     true,
		Stdin:   "hello from stdin\n",

		Stdout:   "hello from stdin\r\nhello from stdin\r\n",
		ExitCode: 0,
	},
	{
		Name:    "tty: children processes",
		Command: "(( sleep 3; echo from background ) & ); echo from main; exec sleep 1",
		Tty:     true,

		Stdout:   "from main\r\n",
		ExitCode: 0,
	},
}

Functions

func ExecTaskStreamingConformanceTests

func ExecTaskStreamingConformanceTests(t *testing.T, driver *DriverHarness, taskID string)

func SetEnvvars

func SetEnvvars(envBuilder *taskenv.Builder, fsi drivers.FSIsolation, taskDir *allocdir.TaskDir, conf *config.Config)

SetEnvvars sets path and host env vars depending on the FS isolation used.

func TestExecFSIsolation

func TestExecFSIsolation(t *testing.T, driver *DriverHarness, taskID string)

TestExecFSIsolation asserts that exec occurs inside chroot/isolation environment rather than on host

func TestExecTaskStreamingBasicResponses

func TestExecTaskStreamingBasicResponses(t *testing.T, driver *DriverHarness, taskID string)

Types

type DriverHarness

type DriverHarness struct {
	drivers.DriverPlugin
	// contains filtered or unexported fields
}

func NewDriverHarness

func NewDriverHarness(t testing.T, d drivers.DriverPlugin) *DriverHarness

func (*DriverHarness) Impl

func (*DriverHarness) Kill

func (h *DriverHarness) Kill()

func (*DriverHarness) MkAllocDir

func (h *DriverHarness) MkAllocDir(t *drivers.TaskConfig, enableLogs bool) func()

MkAllocDir creates a temporary directory and allocdir structure. If enableLogs is set to true a logmon instance will be started to write logs to the LogDir of the task A cleanup func is returned and should be defered so as to not leak dirs between tests.

func (*DriverHarness) WaitUntilStarted

func (h *DriverHarness) WaitUntilStarted(taskID string, timeout time.Duration) error

WaitUntilStarted will block until the task for the given ID is in the running state or the timeout is reached

type MockDriver

type MockDriver struct {
	base.MockPlugin
	TaskConfigSchemaF  func() (*hclspec.Spec, error)
	FingerprintF       func(context.Context) (<-chan *drivers.Fingerprint, error)
	CapabilitiesF      func() (*drivers.Capabilities, error)
	RecoverTaskF       func(*drivers.TaskHandle) error
	StartTaskF         func(*drivers.TaskConfig) (*drivers.TaskHandle, *drivers.DriverNetwork, error)
	WaitTaskF          func(context.Context, string) (<-chan *drivers.ExitResult, error)
	StopTaskF          func(string, time.Duration, string) error
	DestroyTaskF       func(string, bool) error
	InspectTaskF       func(string) (*drivers.TaskStatus, error)
	TaskStatsF         func(context.Context, string, time.Duration) (<-chan *drivers.TaskResourceUsage, error)
	TaskEventsF        func(context.Context) (<-chan *drivers.TaskEvent, error)
	SignalTaskF        func(string, string) error
	ExecTaskF          func(string, []string, time.Duration) (*drivers.ExecTaskResult, error)
	ExecTaskStreamingF func(context.Context, string, *drivers.ExecOptions) (*drivers.ExitResult, error)
}

MockDriver is used for testing. Each function can be set as a closure to make assertions about how data is passed through the base plugin layer.

func (*MockDriver) Capabilities

func (d *MockDriver) Capabilities() (*drivers.Capabilities, error)

func (*MockDriver) DestroyTask

func (d *MockDriver) DestroyTask(taskID string, force bool) error

func (*MockDriver) ExecTask

func (d *MockDriver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*drivers.ExecTaskResult, error)

func (*MockDriver) ExecTaskStreaming

func (d *MockDriver) ExecTaskStreaming(ctx context.Context, taskID string, execOpts *drivers.ExecOptions) (*drivers.ExitResult, error)

func (*MockDriver) Fingerprint

func (d *MockDriver) Fingerprint(ctx context.Context) (<-chan *drivers.Fingerprint, error)

func (*MockDriver) InspectTask

func (d *MockDriver) InspectTask(taskID string) (*drivers.TaskStatus, error)

func (*MockDriver) RecoverTask

func (d *MockDriver) RecoverTask(h *drivers.TaskHandle) error

func (*MockDriver) SignalTask

func (d *MockDriver) SignalTask(taskID string, signal string) error

func (*MockDriver) StartTask

func (*MockDriver) StopTask

func (d *MockDriver) StopTask(taskID string, timeout time.Duration, signal string) error

func (*MockDriver) TaskConfigSchema

func (d *MockDriver) TaskConfigSchema() (*hclspec.Spec, error)

func (*MockDriver) TaskEvents

func (d *MockDriver) TaskEvents(ctx context.Context) (<-chan *drivers.TaskEvent, error)

func (*MockDriver) TaskStats

func (d *MockDriver) TaskStats(ctx context.Context, taskID string, i time.Duration) (<-chan *drivers.TaskResourceUsage, error)

func (*MockDriver) WaitTask

func (d *MockDriver) WaitTask(ctx context.Context, id string) (<-chan *drivers.ExitResult, error)

Jump to

Keyboard shortcuts

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