testutils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Provides a stub implementation of a Deploy Engine server. This allows for thorough testing of the client including client streaming behaviour and the various authentication methods supported by the Deploy Engine v1 API.

Index

Constants

View Source
const (
	// StubAuditRecordID is the ID of the first audit record the stub server holds,
	// the only one it serves by ID.
	StubAuditRecordID = "test-audit-record-id-1"
	// StubSecondAuditRecordID is the ID of the second audit record the stub server holds.
	StubSecondAuditRecordID = "test-audit-record-id-2"
	// StubMissingCursorAction is an action filter that makes the stub server answer a
	// query with a page that reports more records but carries no cursor.
	StubMissingCursorAction = "test.missing-cursor"
)
View Source
const (
	// StubTakenInstanceName is an instance name that the stub server answers a create
	// with as already in use, held by StubNameHolderInstanceID.
	StubTakenInstanceName = "test-taken-instance-name"
	// StubNameHolderInstanceID is the instance that holds StubTakenInstanceName.
	StubNameHolderInstanceID = "test-name-holder-instance-id"
	// StubTakenNameHolderGoneInstanceName is an instance name that the stub server
	// answers a create with as in use, without the holder's ID, as the engine does when
	// the holder is removed before it can be looked up.
	StubTakenNameHolderGoneInstanceName = "test-taken-instance-name-holder-gone"
	// StubOtherInstanceChangesetID is a change set the stub server reports as staged for
	// StubChangesetInstanceID when a create or destroy uses it.
	StubOtherInstanceChangesetID = "test-other-instance-changeset-id"
	// StubChangesetInstanceID is the instance StubOtherInstanceChangesetID was staged for.
	StubChangesetInstanceID = "test-changeset-instance-id"
	// StubNewInstanceChangesetID is a change set the stub server reports as staged for a
	// new instance when an update uses it.
	StubNewInstanceChangesetID = "test-new-instance-changeset-id"
	// StubDriftBlockedChangesetID is a change set the stub server answers an update with
	// as blocked by drift.
	StubDriftBlockedChangesetID = "test-drift-blocked-changeset-id"
)

Variables

This section is empty.

Functions

func CreateDefaultTransport

func CreateDefaultTransport(transport *http.Transport) http.RoundTripper

CreateDefaultTransport provides a function that overrides the default transport configured for a deploy engine client with the Go default HTTP transport.

func CreateDeployEngineServer

func CreateDeployEngineServer(
	serverConfig *TestServerConfig,
	stubValidationEvents []*manage.Event,
	stubChangeStagingEvents []*manage.Event,
	stubDriftDetectedEvents []*manage.Event,
	stubDeploymentEvents []*manage.Event,
	clock core.Clock,
) *httptest.Server

func CreateFailingServer

func CreateFailingServer() *httptest.Server

func CreateOAuthServer

func CreateOAuthServer(
	clientID string, clientSecret string, authType string,
) (*httptest.Server, error)

func NewInstanceState added in v0.6.0

func NewInstanceState(id string, name string, status core.InstanceStatus) *state.InstanceState

NewInstanceState creates the instance the stub engine responds with. Its maps are empty rather than nil, as the deploy engine sends them.

func NewUnixDomainSocketServer

func NewUnixDomainSocketServer(
	socketPath string,
	handler http.Handler,
) *httptest.Server

Types

type MockClock

type MockClock struct {
	TimeSequence []time.Time
	// contains filtered or unexported fields
}

func (*MockClock) Now

func (c *MockClock) Now() time.Time

func (*MockClock) Since

func (c *MockClock) Since(t time.Time) time.Duration

type TestServerConfig

type TestServerConfig struct {
	AllowedAPIKeys                   []string
	AllowedBearerTokens              []string
	AllowedBluelinkSignatureKeyPairs map[string]*sigv1.KeyPair
	// A string that will be present in some part of the request
	// to the server that will trigger behaviour to simulate
	// an internal server error.
	InternalServerErrorTrigger   string
	NetworkErrorTrigger          string
	DeserialiseErrorTrigger      string
	InternalServerErrorTriggerID string
	NetworkErrorTriggerID        string
	DeserialiseErrorTriggerID    string
	FailingStreamTriggerID       string
	DriftDetectedChangesetID     string
	UseUnixDomainSocket          bool
	UnixDomainSocketPath         string
	// Called with the query parameters of each audit trail query the server receives,
	// so tests can check how a client encoded its filters.
	AuditQueryRecorder func(query url.Values)
}

Jump to

Keyboard shortcuts

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