fixture

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package fixture defines the PERF-01 technical fixture: the same five Huma operations served by a standard Huma arm (humago on net/http) and by the adapter arm (humanirvana on a Nirvana router). Both arms share one Huma configuration, so they do equivalent work.

Index

Constants

View Source
const (
	Native  = "native"
	Adapter = "adapter"
)

Arms under comparison.

View Source
const ProtocolRevision = 1

ProtocolRevision identifies the frozen fixture. Changing operations, payloads or expectations requires a new revision and a full re-run.

Variables

View Source
var CaseIDs = []string{"P01", "P02", "P03", "P04", "P05"}

CaseIDs lists the request sets in protocol order.

Functions

func Config

func Config() huma.Config

Config is the Huma configuration both arms use. Schema link hooks are removed so response bodies do not depend on the listening address.

func GenerateBodies

func GenerateBodies() map[string][]byte

GenerateBodies builds the request bodies with their exact byte lengths.

func NewHandler

func NewHandler(arm string) (http.Handler, error)

NewHandler builds one arm.

func WriteManifest

func WriteManifest(dir string) error

WriteManifest records the sha256 of every regular file in dir except the manifest itself.

Types

type Case

type Case struct {
	ID              string            `json:"id"`
	Method          string            `json:"method"`
	Path            string            `json:"path"`
	Header          map[string]string `json:"header"`
	BodyFile        string            `json:"body_file,omitempty"`
	WantStatus      int               `json:"want_status"`
	WantContentType string            `json:"want_content_type"`
	WantBody        string            `json:"want_body"`

	Body []byte `json:"-"`
}

Case is one frozen PERF-01 request set: the exact request and the response every sample must return.

func Load

func Load(dir string) ([]Case, error)

Load reads the frozen cases from dir and verifies every file against MANIFEST.sha256.

func (Case) Check

func (c Case) Check(status int, contentType string, body []byte) error

Check compares a response with the frozen expectation.

func (Case) NewRequest

func (c Case) NewRequest(base string) (*http.Request, error)

NewRequest builds the frozen request against base, e.g. "http://127.0.0.1:1".

type Item

type Item struct {
	ID    int    `json:"id" minimum:"0"`
	Name  string `json:"name" minLength:"1"`
	Attrs struct {
		Color string `json:"color" enum:"red,green,blue"`
		Size  int    `json:"size" minimum:"0"`
	} `json:"attrs"`
}

Item is one P03 entry.

type MiddlewareInput

type MiddlewareInput struct {
	RequestID string `header:"X-Request-ID"`
}

MiddlewareInput is P05.

type MiddlewareOutput

type MiddlewareOutput struct {
	Body struct {
		Order     []string `json:"order"`
		Values    string   `json:"values"`
		RequestID string   `json:"request_id"`
	}
}

MiddlewareOutput returns P05's middleware order and context values.

type NestedInput

type NestedInput struct {
	Body struct {
		Items   []Item `json:"items" minItems:"1" maxItems:"64"`
		Padding string `json:"padding"`
	}
}

NestedInput is P03.

type NestedOutput

type NestedOutput struct {
	Body struct {
		Count int `json:"count"`
	}
}

NestedOutput returns P03's item count.

type ParamsInput

type ParamsInput struct {
	ID      int    `path:"id"`
	Count   int    `query:"count"`
	Enabled bool   `query:"enabled"`
	Tenant  string `header:"X-Tenant"`
}

ParamsInput is P01.

type ParamsOutput

type ParamsOutput struct {
	Body struct {
		ID      int    `json:"id"`
		Count   int    `json:"count"`
		Enabled bool   `json:"enabled"`
		Tenant  string `json:"tenant"`
	}
}

ParamsOutput echoes P01's parsed values.

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink is an in-memory log written by the P05 middleware; it does no I/O.

func Register

func Register(api huma.API) *Sink

Register adds P01–P05 to api and returns the P05 log sink.

func (*Sink) Writes

func (s *Sink) Writes() uint64

Writes returns the number of log entries written.

type SmallBody

type SmallBody struct {
	Quantity int    `json:"quantity" minimum:"1"`
	Padding  string `json:"padding"`
}

SmallBody is the P02/P04 request body.

type SmallInput

type SmallInput struct {
	Body SmallBody
}

SmallInput is P02 and P04.

type SmallOutput

type SmallOutput struct {
	Body struct {
		Accepted bool `json:"accepted"`
		Quantity int  `json:"quantity"`
	}
}

SmallOutput confirms P02.

Jump to

Keyboard shortcuts

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