fixtures

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

README

These fixtures were created by adding logging middleware to API calls to view the raw requests/responses.

...
opts = append(opts, option.WithMiddleware(LoggingMiddleware))
...

func LoggingMiddleware(req *http.Request, next option.MiddlewareNext) (res *http.Response, err error) {
    reqOut, _ := httputil.DumpRequest(req, true)

    // Forward the request to the next handler
    res, err = next(req)
    fmt.Printf("[req] %s\n", reqOut)

    // Handle stuff after the request
    if err != nil {
        return res, err
    }

    respOut, _ := httputil.DumpResponse(res, true)
    fmt.Printf("[resp] %s\n", respOut)

    return res, err
}

Documentation

Index

Constants

View Source
const (

	// Exported aliases so callers can check [Fixture.Has] before calling a
	// getter that would otherwise fail the test.
	SectionStreaming         = fileStreamingResponse
	SectionNonStreaming      = fileNonStreamingResponse
	SectionStreamingToolCall = fileStreamingToolCall
	SectionNonStreamToolCall = fileNonStreamingToolCall
)

Section name constants matching the file names used in txtar fixtures.

Variables

View Source
var (
	//go:embed anthropic/simple.txtar
	AntSimple []byte

	//go:embed anthropic/single_builtin_tool.txtar
	AntSingleBuiltinTool []byte

	//go:embed anthropic/single_injected_tool.txtar
	AntSingleInjectedTool []byte

	//go:embed anthropic/fallthrough.txtar
	AntFallthrough []byte

	//go:embed anthropic/stream_error.txtar
	AntMidStreamError []byte

	//go:embed anthropic/non_stream_error.txtar
	AntNonStreamError []byte
)
View Source
var (
	//go:embed openai/chatcompletions/simple.txtar
	OaiChatSimple []byte

	//go:embed openai/chatcompletions/single_builtin_tool.txtar
	OaiChatSingleBuiltinTool []byte

	//go:embed openai/chatcompletions/single_injected_tool.txtar
	OaiChatSingleInjectedTool []byte

	//go:embed openai/chatcompletions/fallthrough.txtar
	OaiChatFallthrough []byte

	//go:embed openai/chatcompletions/stream_error.txtar
	OaiChatMidStreamError []byte

	//go:embed openai/chatcompletions/non_stream_error.txtar
	OaiChatNonStreamError []byte

	//go:embed openai/chatcompletions/streaming_injected_tool_no_preamble.txtar
	OaiChatStreamingInjectedToolNoPreamble []byte

	//go:embed openai/chatcompletions/streaming_injected_tool_nonzero_index.txtar
	OaiChatStreamingInjectedToolNonzeroIndex []byte
)
View Source
var (
	//go:embed openai/responses/blocking/simple.txtar
	OaiResponsesBlockingSimple []byte

	//go:embed openai/responses/blocking/single_builtin_tool.txtar
	OaiResponsesBlockingSingleBuiltinTool []byte

	//go:embed openai/responses/blocking/cached_input_tokens.txtar
	OaiResponsesBlockingCachedInputTokens []byte

	//go:embed openai/responses/blocking/custom_tool.txtar
	OaiResponsesBlockingCustomTool []byte

	//go:embed openai/responses/blocking/conversation.txtar
	OaiResponsesBlockingConversation []byte

	//go:embed openai/responses/blocking/http_error.txtar
	OaiResponsesBlockingHttpErr []byte

	//go:embed openai/responses/blocking/prev_response_id.txtar
	OaiResponsesBlockingPrevResponseID []byte

	//go:embed openai/responses/blocking/single_injected_tool.txtar
	OaiResponsesBlockingSingleInjectedTool []byte

	//go:embed openai/responses/blocking/single_injected_tool_error.txtar
	OaiResponsesBlockingSingleInjectedToolError []byte

	//go:embed openai/responses/blocking/wrong_response_format.txtar
	OaiResponsesBlockingWrongResponseFormat []byte
)
View Source
var (
	//go:embed openai/responses/streaming/simple.txtar
	OaiResponsesStreamingSimple []byte

	//go:embed openai/responses/streaming/codex_example.txtar
	OaiResponsesStreamingCodex []byte

	//go:embed openai/responses/streaming/builtin_tool.txtar
	OaiResponsesStreamingBuiltinTool []byte

	//go:embed openai/responses/streaming/cached_input_tokens.txtar
	OaiResponsesStreamingCachedInputTokens []byte

	//go:embed openai/responses/streaming/custom_tool.txtar
	OaiResponsesStreamingCustomTool []byte

	//go:embed openai/responses/streaming/conversation.txtar
	OaiResponsesStreamingConversation []byte

	//go:embed openai/responses/streaming/http_error.txtar
	OaiResponsesStreamingHttpErr []byte

	//go:embed openai/responses/streaming/prev_response_id.txtar
	OaiResponsesStreamingPrevResponseID []byte

	//go:embed openai/responses/streaming/single_injected_tool.txtar
	OaiResponsesStreamingSingleInjectedTool []byte

	//go:embed openai/responses/streaming/single_injected_tool_error.txtar
	OaiResponsesStreamingSingleInjectedToolError []byte

	//go:embed openai/responses/streaming/stream_error.txtar
	OaiResponsesStreamingStreamError []byte

	//go:embed openai/responses/streaming/stream_failure.txtar
	OaiResponsesStreamingStreamFailure []byte

	//go:embed openai/responses/streaming/wrong_response_format.txtar
	OaiResponsesStreamingWrongResponseFormat []byte
)

Functions

func Request

func Request(t *testing.T, fixture []byte) []byte

Request extracts the "request" fixture from raw txtar data.

Types

type Fixture added in v1.0.7

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

Fixture holds the named sections of a parsed txtar test fixture.

func Parse added in v1.0.7

func Parse(t *testing.T, data []byte) Fixture

Parse parses raw txtar data into a Fixture.

func (Fixture) Has added in v1.0.7

func (f Fixture) Has(name string) bool

Has reports whether the fixture contains the named section.

func (Fixture) NonStreaming added in v1.0.7

func (f Fixture) NonStreaming() []byte

func (Fixture) NonStreamingToolCall added in v1.0.7

func (f Fixture) NonStreamingToolCall() []byte

func (Fixture) Request added in v1.0.7

func (f Fixture) Request() []byte

func (Fixture) Streaming added in v1.0.7

func (f Fixture) Streaming() []byte

func (Fixture) StreamingToolCall added in v1.0.7

func (f Fixture) StreamingToolCall() []byte

Jump to

Keyboard shortcuts

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