workertest

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package workertest provides a framework for declarative definition of worker integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllOfArtifact added in v0.1.17

func AllOfArtifact(assertions ...func(t *testing.T, a Artifact)) func(t *testing.T, a Artifact)

AllOfArtifact creates an assertion that checks all assertions given

func AnyArtifact

func AnyArtifact() func(t *testing.T, a Artifact)

AnyArtifact creates an assertion that checks matches anything.

func ErrorArtifact

func ErrorArtifact() func(t *testing.T, a Artifact)

ErrorArtifact creates an assertion that holds if the artifact is an error artifact

func GrepArtifact

func GrepArtifact(substring string) func(t *testing.T, a Artifact)

GrepArtifact creates an assertion that holds if the artifact contains the given substring.

func LogArtifact added in v0.1.1

func LogArtifact() func(t *testing.T, a Artifact)

LogArtifact creates an assetion that logs the artifact, to test log. This is mostly useful when developing integration tests.

func MatchArtifact added in v0.1.1

func MatchArtifact(body, contentType string) func(t *testing.T, a Artifact)

MatchArtifact creates an assertion that holds if the artifact body matches given body and has the given contentType

func NotGrepArtifact added in v0.1.12

func NotGrepArtifact(substring string) func(t *testing.T, a Artifact)

NotGrepArtifact creates an assertion that holds if the artifact does not contain the given substring.

func ReferenceArtifact

func ReferenceArtifact() func(t *testing.T, a Artifact)

ReferenceArtifact creates an assertion that holds if the artifact is a reference artifact

func S3Artifact

func S3Artifact() func(t *testing.T, a Artifact)

S3Artifact creates an assertion that holds if the artifact is an S3 artifact

Types

type Artifact

type Artifact struct {
	ContentType     string
	Expires         time.Time
	Name            string
	StorageType     string
	Data            []byte
	ContentEncoding string
}

Artifact contains artifact meta-data.

type ArtifactAssertions

type ArtifactAssertions map[string]func(t *testing.T, a Artifact)

An ArtifactAssertions is a mapping from artifact name to assertion for the artifact. If mapping to nil value, any artifact will be permitted.

type Case

type Case struct {
	Engine            string        // Engine to be used
	EngineConfig      string        // Engine configuration as JSON
	PluginConfig      string        // Configuration of plugins, see plugins.PluginManagerConfigSchema()
	Setup             SetupFunc     // Function to setup local environment, return a cleanup function
	Tasks             TasksFunc     // Function that returns a list of tasks to create and associated assertions
	Concurrency       int           // Worker concurrency, if zero defaulted to 1 and tasks will sequantially dependent
	StoppedGracefully bool          // True, if worker is expected to stop gracefully
	StoppedNow        bool          // True, if worker is expected to stop now
	Timeout           time.Duration // Test timeout, defaults to 8 Minutes
	EnableSuperseding bool          // Enable superseding in the worker
}

Case is a worker test case

func (Case) Test

func (c Case) Test(t *testing.T)

Test runs the test case

func (Case) TestWithFakeQueue

func (c Case) TestWithFakeQueue(t *testing.T)

TestWithFakeQueue runs integration tests against FakeQueue

func (Case) TestWithRealQueue

func (c Case) TestWithRealQueue(t *testing.T)

TestWithRealQueue runs integration tests against production queue

type Environment added in v0.1.16

type Environment struct {
	Worker   runtime.Stoppable
	Queue    *tcqueue.Queue
	Listener fakequeue.Listener
}

Environment holds values that can be accessed in callbacks

type SetupFunc added in v0.1.16

type SetupFunc func(t *testing.T, env Environment) func()

A SetupFunc callback can setup the local environment, this includes starting servers running on localhost. The SetupFunc callback returns a cleanup function that will be invoked when tests are done.

type StatusAssertion

type StatusAssertion func(t *testing.T, q *tcqueue.Queue, status tcqueue.TaskStatusStructure)

A StatusAssertion is a function that can make an assertion on a task status

type Task

type Task struct {
	TaskID          string                  // Optional taskID (use slugid.Nice())
	Title           string                  // Optional title (for debugging)
	Scopes          []string                // Task scopes
	Payload         string                  // Task payload as JSON
	IgnoreState     bool                    // Ignore Success and Exception
	Success         bool                    // True, if task should be successfully
	Exception       runtime.ExceptionReason // Reason, if exception is expected
	Artifacts       ArtifactAssertions      // Mapping from artifact name to assertion
	AllowAdditional bool                    // True, if additional artifacts is allowed
	Status          StatusAssertion         // Optional, custom assertion on status and queue
}

A Task to be included in a worker test case

type TasksFunc added in v0.1.16

type TasksFunc func(t *testing.T, env Environment) []Task

A TasksFunc callback returns the tasks to be created and associated assertions.

For test cases that uses a static list of tasks, Tasks([]task{...}) function can be used to wrap a static []Task list.

func Tasks added in v0.1.16

func Tasks(tasks []Task) TasksFunc

Tasks is a quick wrapper for constructing a TasksFunc that always returns a static list of tasks.

Directories

Path Synopsis
Package fakequeue provides a fake implementation of taskcluster-queue in golang, The FakeQueue server stores tasks in-memory, it doesn't validate authentication, but implements most end-points correctly.
Package fakequeue provides a fake implementation of taskcluster-queue in golang, The FakeQueue server stores tasks in-memory, it doesn't validate authentication, but implements most end-points correctly.

Jump to

Keyboard shortcuts

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