Documentation
¶
Index ¶
- Constants
- func ErrorResponse(status int) http.HandlerFunc
- func JSONResponse(body string) http.HandlerFunc
- func MethodAwareHandler(handlers map[string]http.HandlerFunc) http.HandlerFunc
- func NewMockEnterpriseServer(t *testing.T, cfg MockServerConfig) *httptest.Server
- func NewMockServer(t *testing.T, cfg MockServerConfig) *httptest.Server
- func NewTestClient(t *testing.T, server *httptest.Server) *client.DataplaneClient
- func StatusResponse(status int) http.HandlerFunc
- func TextResponse(status int, body string) http.HandlerFunc
- type MockServerConfig
Constants ¶
const ( TestUsername = "admin" TestPassword = "password" )
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 ¶
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.