fixtures

package
v2.38.8 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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/multi_thinking_builtin_tool.txtar
	AntMultiThinkingBuiltinTool []byte

	//go:embed anthropic/single_builtin_tool_parallel.txtar
	AntSingleBuiltinToolParallel []byte

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

	//go:embed anthropic/single_injected_tool_no_preamble.txtar
	AntSingleInjectedToolNoPreamble []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

	//go:embed anthropic/simple_bedrock.txtar
	AntSimpleBedrock []byte

	//go:embed anthropic/haiku_simple.txtar
	AntHaikuSimple []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

	//go:embed openai/chatcompletions/streaming_cumulative_usage_injected_tool.txtar
	OaiChatStreamingCumulativeUsageInjectedTool []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/multi_reasoning_builtin_tool.txtar
	OaiResponsesBlockingMultiReasoningBuiltinTool []byte

	//go:embed openai/responses/blocking/commentary_builtin_tool.txtar
	OaiResponsesBlockingCommentaryBuiltinTool []byte

	//go:embed openai/responses/blocking/summary_and_commentary_builtin_tool.txtar
	OaiResponsesBlockingSummaryAndCommentaryBuiltinTool []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/web_search.txtar
	OaiResponsesBlockingWebSearch []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_builtin_tool_parallel.txtar
	OaiResponsesBlockingSingleBuiltinToolParallel []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/web_search.txtar
	OaiResponsesStreamingWebSearch []byte

	//go:embed openai/responses/streaming/multi_reasoning_builtin_tool.txtar
	OaiResponsesStreamingMultiReasoningBuiltinTool []byte

	//go:embed openai/responses/streaming/commentary_builtin_tool.txtar
	OaiResponsesStreamingCommentaryBuiltinTool []byte

	//go:embed openai/responses/streaming/summary_and_commentary_builtin_tool.txtar
	OaiResponsesStreamingSummaryAndCommentaryBuiltinTool []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_builtin_tool_parallel.txtar
	OaiResponsesStreamingSingleBuiltinToolParallel []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

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

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

func Parse

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

Parse parses raw txtar data into a Fixture.

func (Fixture) Has

func (f Fixture) Has(name string) bool

Has reports whether the fixture contains the named section.

func (Fixture) NonStreaming

func (f Fixture) NonStreaming() []byte

func (Fixture) NonStreamingToolCall

func (f Fixture) NonStreamingToolCall() []byte

func (Fixture) Request

func (f Fixture) Request() []byte

func (Fixture) Streaming

func (f Fixture) Streaming() []byte

func (Fixture) StreamingToolCall

func (f Fixture) StreamingToolCall() []byte

Jump to

Keyboard shortcuts

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