testserver

package
v0.32.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoModules

func NoModules(options modules.Options) []modules.Initializer

NoModules can be used to start a test server without any modules. This is useful for testing the server itself and core functionality like planes.

Types

type TestResponse

type TestResponse struct {
	Raw   *http.Response
	Body  *bytes.Buffer
	Error *v1.ErrorResponse
	// contains filtered or unexported fields
}

TestResponse is return from requests made against a TestServer. Tests should use the functions defined on TestResponse for valiation.

func (*TestResponse) EqualsErrorCode

func (tr *TestResponse) EqualsErrorCode(statusCode int, code string)

EqualsErrorCode compares a TestResponse against an expected status code and error code. EqualsErrorCode assumes the response uses the ARM error format (required for our APIs).

func (*TestResponse) EqualsFixture

func (tr *TestResponse) EqualsFixture(statusCode int, fixture string)

EqualsFixture compares a TestResponse against an expected status code and body payload. Use the fixture parameter to specify the path to a file.

func (*TestResponse) EqualsResponse

func (tr *TestResponse) EqualsResponse(statusCode int, body []byte)

EqualsFixture compares a TestResponse against an expected status code and body payload.

func (*TestResponse) EqualsStatusCode

func (tr *TestResponse) EqualsStatusCode(statusCode int)

EqualsStatusCode compares a TestResponse against an expected status code (ingnores the body payload).

type TestServer

type TestServer struct {
	// BaseURL is the base URL of the server, including the path base.
	BaseURL string

	// Clients gets access to the clients created by TestServer regardless of whether
	// they are mocks.
	Clients *TestServerClients

	// Mocks gets access to the mock clients. Will be nil if StartWithETCD is used.
	Mocks *TestServerMocks

	// Server provides access to the test HTTP server.
	Server *httptest.Server
	// contains filtered or unexported fields
}

TestServer can run a UCP server using the Go httptest package. It provides access to an isolated ETCD instances for storage of resources and secrets. Alteratively, it can also be used with gomock.

Do not create a TestServer directly, use StartWithETCD or StartWithMocks instead.

func StartWithETCD

func StartWithETCD(t *testing.T, configureModules func(options modules.Options) []modules.Initializer) *TestServer

StartWithETCD creates and starts a new TestServer that used an embedded ETCD instance for storage.

func StartWithMocks

func StartWithMocks(t *testing.T, configureModules func(options modules.Options) []modules.Initializer) *TestServer

StartWithMocks creates and starts a new TestServer that used an mocks for storage.

func (*TestServer) Client

func (ts *TestServer) Client() *http.Client

Client provides access to an http.Client that can be used to send requests. Most tests should use the functionality like MakeRequest instead of testing the client directly.

func (*TestServer) Close

func (ts *TestServer) Close()

Close shuts down the server and will block until shutdown completes.

func (*TestServer) MakeFixtureRequest

func (ts *TestServer) MakeFixtureRequest(method string, pathAndQuery string, fixture string) *TestResponse

MakeFixtureRequest sends a request to the server using a file on disk as the payload (body). Use the fixture parameter to specify the path to a file.

func (*TestServer) MakeRequest

func (ts *TestServer) MakeRequest(method string, pathAndQuery string, body []byte) *TestResponse

MakeRequest sends a request to the server.

func (*TestServer) MakeTypedRequest

func (ts *TestServer) MakeTypedRequest(method string, pathAndQuery string, body any) *TestResponse

MakeTypedRequest sends a request to the server by marshalling the provided object to JSON.

type TestServerClients

type TestServerClients struct {
	// QueueProvider is the queue client provider.
	QueueProvider *queueprovider.QueueProvider

	// SecretProvider is the secret client provider.
	SecretProvider *secretprovider.SecretProvider

	// StorageProvider is the storage client provider.
	StorageProvider dataprovider.DataStorageProvider
}

TestServerClients provides access to the clients created by the TestServer.

type TestServerMocks

type TestServerMocks struct {
	// Secrets is the mock secret client.
	Secrets *secret.MockClient

	// Storage is the mock storage client.
	Storage *store.MockStorageClient
}

TestServerMocks provides access to mock instances created by the TestServer.

Jump to

Keyboard shortcuts

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