testutil

package
v0.1.0-alpha.12 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestUsername = "admin"
	TestPassword = "password"
)
View Source
const (
	CommunityAPIVersion  = "v3.2.6 87ad0bcf"
	EnterpriseAPIVersion = "v3.2.6-ee1"
)

Variables

This section is empty.

Functions

func ErrorResponse

func ErrorResponse(status int) http.HandlerFunc

ErrorResponse creates a handler that returns an error status with no body.

func JSONResponse

func JSONResponse(body string) http.HandlerFunc

JSONResponse creates a handler that returns JSON with http.StatusOK.

func MethodAwareHandler

func MethodAwareHandler(handlers map[string]http.HandlerFunc) http.HandlerFunc

MethodAwareHandler creates a handler that responds differently based on HTTP method.

func NewMockEnterpriseServer

func NewMockEnterpriseServer(t *testing.T, cfg MockServerConfig) *httptest.Server

NewMockEnterpriseServer creates a test server that mimics the Enterprise Dataplane API. It provides the same /v3/info endpoint but also tries to match handlers with and without the /v3 prefix, which mirrors how the enterprise API routes requests.

func NewMockServer

func NewMockServer(t *testing.T, cfg MockServerConfig) *httptest.Server

NewMockServer creates a test server that mimics the Dataplane API. It always provides a /v3/info endpoint returning the configured API version.

func NewTestClient

func NewTestClient(t *testing.T, server *httptest.Server) *client.DataplaneClient

NewTestClient creates a client connected to a test server.

func StatusResponse

func StatusResponse(status int) http.HandlerFunc

StatusResponse creates a handler that returns a specific status code. This is an alias for ErrorResponse, named for clarity when the status is not an error.

func TextResponse

func TextResponse(status int, body string) http.HandlerFunc

TextResponse creates a handler that returns plain text with the given status code.

Types

type MockServerConfig

type MockServerConfig struct {
	// APIVersion is returned by the /v3/info endpoint.
	// Defaults to CommunityAPIVersion or EnterpriseAPIVersion depending on server type.
	APIVersion string

	// Handlers maps URL paths to handler functions.
	Handlers map[string]http.HandlerFunc
}

MockServerConfig configures a mock Dataplane API server for tests.

Jump to

Keyboard shortcuts

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