Documentation
¶
Index ¶
- func CaptureStdout(t *testing.T, f func()) string
- func CaptureStdoutWithLevel(t *testing.T, level slog.Level, f func()) string
- func CreateTempYAMLFile(t *testing.T, dir string, name string, content string) string
- func NewMockDockerClient(t *testing.T, roundTripFunc func(req *http.Request) (*http.Response, error)) *client.Client
- func SetupMockExecutable(t *testing.T, cmdName string, scriptContent string) (string, func())
- func StartMockJaegerServer(t *testing.T, handler func(traceID string) (any, int)) *httptest.Server
- func StartMockNATSServer(t *testing.T, enableJetstream bool) string
- func StartMockNATSServerWithOptions(t *testing.T, opts *natsserver.Options) string
- func StartMockOpenObserveServer(t *testing.T, handler func(sqlQuery string) ([]map[string]any, int)) *httptest.Server
- type GRPCRequestRecord
- type GRPCTargetServer
- type HTTPRequestRecord
- type HTTPTargetServer
- type MockIdGenerator
- type MockRoundTripper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureStdout ¶
CaptureStdout captures the standard output generated during the execution of f. It forces the slog logger to LevelDebug for the duration of the capture.
func CaptureStdoutWithLevel ¶
CaptureStdoutWithLevel captures the standard output generated during the execution of f, and sets the slog logger to the specified level for the duration of the capture.
func CreateTempYAMLFile ¶
CreateTempYAMLFile creates a temporary .mt.yaml file with the given content. It automatically cleans up the file when the test finishes.
func NewMockDockerClient ¶
func SetupMockExecutable ¶
SetupMockExecutable creates a mock executable shell script in a temporary bin directory, prepends that directory to the PATH environment variable, and returns the path to a log file where invocation arguments are recorded, along with a cleanup function.
cmdName is the name of the command to mock (e.g. "npx" or "docker"). scriptContent is the shell script body. If empty, a default script is used that logs arguments and exits with 0 (or 1 if MTRACE_TEST_FAIL env var is "true").
func StartMockJaegerServer ¶
StartMockJaegerServer starts a mock HTTP server that simulates Jaeger trace search endpoint.
func StartMockNATSServer ¶
StartMockNATSServer starts an in-memory NATS server on a random port. If enableJetstream is true, JetStream is initialized using a temp directory. Returns the connection address (without the "nats://" scheme).
func StartMockNATSServerWithOptions ¶
func StartMockNATSServerWithOptions(t *testing.T, opts *natsserver.Options) string
StartMockNATSServerWithOptions starts an in-memory NATS server with the given Options. Returns the connection address (without the "nats://" scheme).
func StartMockOpenObserveServer ¶
func StartMockOpenObserveServer(t *testing.T, handler func(sqlQuery string) ([]map[string]any, int)) *httptest.Server
StartMockOpenObserveServer starts a mock HTTP server that simulates OpenObserve trace search endpoint. The handler receives the SQL query string and returns the list of hits and HTTP status code.
Types ¶
type GRPCRequestRecord ¶
GRPCRequestRecord records details of a gRPC request received by the mock server.
type GRPCTargetServer ¶
type GRPCTargetServer struct {
Address string
Server *grpc.Server
Requests []GRPCRequestRecord
}
GRPCTargetServer is a mock gRPC server.
func StartGRPCTargetServer ¶
func StartGRPCTargetServer(t *testing.T, baseDir string, protoPath string, serviceName string, responseData map[string]any) *GRPCTargetServer
StartGRPCTargetServer starts a mock gRPC server on a local port. It uses the proto files to decode incoming requests dynamically.
type HTTPRequestRecord ¶
HTTPRequestRecord represents a recorded request received by the mock target server.
type HTTPTargetServer ¶
type HTTPTargetServer struct {
Server *httptest.Server
Requests []HTTPRequestRecord
}
HTTPTargetServer represents a mock HTTP target server.
func StartHTTPTargetServer ¶
func StartHTTPTargetServer(t *testing.T, responseBody string, statusCode int) *HTTPTargetServer
StartHTTPTargetServer starts a mock HTTP target server that records requests.