Help us shape the future of Go! Take the 2026 Go Developer Survey

testhost

package
v0.60.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testhost provides a host for running any Radius control-plane component as an in-memory server for testing purposes.

This package should be wrapped in a test package specific to the component under test. The wrapping design allows for component-specific depenendendencies to be defined without polluting the shared code.

Package testhost provides a host for running any Radius control-plane component as an in-memory server for testing purposes.

This package should be wrapped in a test package specific to the component under test. The wrapping design allows for component-specific depenendendencies to be defined without polluting the shared code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllocateFreePort

func AllocateFreePort(t *testing.T) int

AllocateFreePort chooses a random port for use in tests.

Types

type TestHost

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

TestHost is a test server for any Radius control-plane component. Do not construct this type directly, use the Start function.

func StartHost

func StartHost(t *testing.T, host *hosting.Host, baseURL string) *TestHost

StartHost starts a new test host for the given hosting.Host and returns a TestHost instance. The TestHost will have its lifecycle managed by the test context, and will be shut down when the test completes.

func (*TestHost) BaseURL

func (th *TestHost) BaseURL() string

BaseURL returns the base URL of the server, including the path base.

This should be used as a URL prefix for all requests to the server.

func (*TestHost) Client

func (th *TestHost) Client() *http.Client

Client returns the HTTP client to use to make requests to the server.

func (*TestHost) Close

func (th *TestHost) Close()

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

func (*TestHost) MakeFixtureRequest

func (th *TestHost) 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 (*TestHost) MakeRequest

func (th *TestHost) MakeRequest(method string, pathAndQuery string, body []byte) *TestResponse

MakeRequest sends a request to the server.

func (*TestHost) MakeTypedRequest

func (th *TestHost) MakeTypedRequest(method string, pathAndQuery string, body any) *TestResponse

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

func (*TestHost) T

func (th *TestHost) T() *testing.T

T returns the testing.T instance associated with the test host.

type TestResponse

type TestResponse struct {
	// Raw is the raw HTTP response.
	Raw *http.Response

	// Body is the response body.
	Body *bytes.Buffer

	// Error is the ARM error response if the response status code is >= 400.
	Error *v1.ErrorResponse
	// contains filtered or unexported fields
}

TestResponse is returned from requests made against a TestHost. Tests should use the functions defined on TestResponse for validation.

func (*TestResponse) EqualsEmptyList

func (tr *TestResponse) EqualsEmptyList()

EqualsEmptyList compares a TestResponse against an expected status code and an empty resource list.

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).

func (*TestResponse) EqualsValue

func (tr *TestResponse) EqualsValue(statusCode int, expected any)

EqualsValue compares a TestResponse against an expected status code and an response body.

If the systemData propert is present in the response, it will be removed.

func (*TestResponse) ReadAs

func (tr *TestResponse) ReadAs(obj any)

func (*TestResponse) WaitForOperationComplete

func (tr *TestResponse) WaitForOperationComplete(timeout *time.Duration) *TestResponse

Jump to

Keyboard shortcuts

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