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 ¶
- func AllocateFreePort(t *testing.T) int
- type TestHost
- func (th *TestHost) BaseURL() string
- func (th *TestHost) Client() *http.Client
- func (th *TestHost) Close()
- func (th *TestHost) MakeFixtureRequest(method string, pathAndQuery string, fixture string) *TestResponse
- func (th *TestHost) MakeRequest(method string, pathAndQuery string, body []byte) *TestResponse
- func (th *TestHost) MakeTypedRequest(method string, pathAndQuery string, body any) *TestResponse
- func (th *TestHost) T() *testing.T
- type TestResponse
- func (tr *TestResponse) EqualsEmptyList()
- func (tr *TestResponse) EqualsErrorCode(statusCode int, code string)
- func (tr *TestResponse) EqualsFixture(statusCode int, fixture string)
- func (tr *TestResponse) EqualsResponse(statusCode int, body []byte)
- func (tr *TestResponse) EqualsStatusCode(statusCode int)
- func (tr *TestResponse) EqualsValue(statusCode int, expected any)
- func (tr *TestResponse) ReadAs(obj any)
- func (tr *TestResponse) WaitForOperationComplete(timeout *time.Duration) *TestResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllocateFreePort ¶
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 ¶
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 ¶
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) 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.
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