Documentation
¶
Overview ¶
Package mockapi provides a mock Central API server for end-to-end testing. It returns fixture responses for each endpoint and tracks call counters that can be queried via the GET /test/assertions endpoint.
Index ¶
- Constants
- func GenerateSelfSignedTLSConfig() *tls.Config
- type AssertionCounters
- type Server
- func (s *Server) Assertions() AssertionCounters
- func (s *Server) BroadcastSSE(envelope api.SignedEnvelope)
- func (s *Server) ExpectedBearerToken() string
- func (s *Server) GetState() api.StateResponse
- func (s *Server) Handler() http.Handler
- func (s *Server) LastRequestBody(endpoint string) ([]byte, bool)
- func (s *Server) NSK() []byte
- func (s *Server) SetHeartbeatResponse(resp api.HeartbeatResponse)
- func (s *Server) SetState(state api.StateResponse)
- func (s *Server) TLSHandler() http.Handler
Constants ¶
const DefaultKeepAliveInterval = 15 * time.Second
DefaultKeepAliveInterval is the default interval between SSE keep-alive comments.
Variables ¶
This section is empty.
Functions ¶
func GenerateSelfSignedTLSConfig ¶
GenerateSelfSignedTLSConfig creates a self-signed TLS configuration with an ECDSA key and X.509 certificate valid for "mock-api" and "localhost".
Types ¶
type AssertionCounters ¶
type AssertionCounters struct {
RegisterCount int64 `json:"registration_count"`
HeartbeatCount int64 `json:"heartbeat_count"`
StateCount int64 `json:"state_count"`
MetadataCount int64 `json:"metadata_count"`
DeregisterCount int64 `json:"deregister_count"`
KeyRotateCount int64 `json:"key_rotate_count"`
CapabilitiesCount int64 `json:"capabilities_count"`
EndpointCount int64 `json:"endpoint_count"`
DriftCount int64 `json:"drift_count"`
SecretsCount int64 `json:"secrets_count"`
ReportCount int64 `json:"report_count"`
ExecutionAckCount int64 `json:"execution_ack_count"`
ExecutionResultCount int64 `json:"execution_result_count"`
MetricsCount int64 `json:"metrics_count"`
LogsCount int64 `json:"logs_count"`
AuditCount int64 `json:"audit_count"`
ArtifactCount int64 `json:"artifact_count"`
TunnelReadyCount int64 `json:"tunnel_ready_count"`
TunnelClosedCount int64 `json:"tunnel_closed_count"`
IntegrityViolationCount int64 `json:"integrity_violation_count"`
InjectEventCount int64 `json:"inject_event_count"`
LocalMetricsCount int64 `json:"local_metrics_count"`
LocalLogsCount int64 `json:"local_logs_count"`
LocalAuditCount int64 `json:"local_audit_count"`
}
AssertionCounters holds call counters for each tracked endpoint.
type Server ¶
type Server struct {
// KeepAliveInterval controls the SSE keep-alive comment interval.
// Defaults to DefaultKeepAliveInterval (15s). Set before calling Handler().
KeepAliveInterval time.Duration
// contains filtered or unexported fields
}
Server is a mock Central API server that returns fixture data.
func (*Server) Assertions ¶
func (s *Server) Assertions() AssertionCounters
Assertions returns a snapshot of the current call counters.
func (*Server) BroadcastSSE ¶
func (s *Server) BroadcastSSE(envelope api.SignedEnvelope)
BroadcastSSE sends an SSE event to all connected SSE clients.
func (*Server) ExpectedBearerToken ¶
ExpectedBearerToken returns the expected bearer token (for testing).
func (*Server) GetState ¶
func (s *Server) GetState() api.StateResponse
GetState returns a copy of the current state fixture.
func (*Server) LastRequestBody ¶
LastRequestBody returns the last captured request body for the given endpoint.
func (*Server) SetHeartbeatResponse ¶
func (s *Server) SetHeartbeatResponse(resp api.HeartbeatResponse)
SetHeartbeatResponse updates the mutable heartbeat response fixture.
func (*Server) SetState ¶
func (s *Server) SetState(state api.StateResponse)
SetState updates the mutable state fixture returned by GET /v1/nodes/{id}/state.
func (*Server) TLSHandler ¶
TLSHandler returns an http.Handler for the local endpoint TLS listener. It registers local endpoint routes plus test assertion/last-request routes.