tests

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package tests provides a ready made oida-instrumented server for use in tests and examples: a chi router with the tracing middleware, the debug front end mounted, memory storage, and a handful of routes that record spans.

Example (MountServeMux)

Example_mountServeMux mounts the tracer's dashboard on the standard library mux: the tracer is an http.Handler, so Handle is the whole integration.

package main

import (
	"fmt"
	"net/http"
	"net/http/httptest"

	"github.com/titpetric/oida"
)

func main() {
	opts := oida.NewOptions("billing-api")
	opts.Enabled = true

	tracer, err := oida.New(opts)
	if err != nil {
		fmt.Println(err)
		return
	}

	mux := http.NewServeMux()
	mux.Handle("/debug/oida/", tracer)

	response := httptest.NewRecorder()
	mux.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/debug/oida/", nil))
	fmt.Println(response.Code)
}
Output:
200

Index

Examples

Constants

View Source
const Path = "/debug/oida"

Path is the mount path of the debug front end on the test server.

Variables

This section is empty.

Functions

func NewHTTPServer

func NewHTTPServer(t testing.TB) *httptest.Server

NewHTTPServer starts NewServer on a local listener and closes it when the test ends.

func NewServer

func NewServer(t testing.TB) http.Handler

NewServer returns a chi router with oida wired in: the tracing middleware, the debug front end mounted under Path, and sample routes that record spans. Recording and storage failures fail the test.

func NewServerWithTracer

func NewServerWithTracer(t testing.TB) (http.Handler, *oida.Tracer)

NewServerWithTracer returns the same router as NewServer together with the tracer recording it, so tests can assert on the recorded traces directly.

Types

This section is empty.

Jump to

Keyboard shortcuts

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