test

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTestErrorAccumulatorWriteFailed = errors.New("test error accumulator failed")
)

Functions

func CreateTestDirectory added in v1.8.0

func CreateTestDirectory(t *testing.T) (path string, cleanup func())

CreateTestDirectory creates a temporary folder which will be deleted when cleanup is called.

func CreateTestFile added in v1.8.0

func CreateTestFile(t *testing.T, path string)

CreateTestFile creates a fake file with "hello" as the content.

func GetTestToken

func GetTestToken() string

Types

type FailingErrorBuffer added in v1.10.0

type FailingErrorBuffer struct{}

func (*FailingErrorBuffer) Bytes added in v1.10.0

func (b *FailingErrorBuffer) Bytes() []byte

func (*FailingErrorBuffer) Len added in v1.10.0

func (b *FailingErrorBuffer) Len() int

func (*FailingErrorBuffer) Write added in v1.10.0

func (b *FailingErrorBuffer) Write(_ []byte) (n int, err error)

type ServerTest

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

func NewTestServer

func NewTestServer() *ServerTest

func (*ServerTest) OpenAITestServer

func (ts *ServerTest) OpenAITestServer() *httptest.Server

OpenAITestServer Creates a mocked OpenAI server which can pretend to handle requests during testing.

func (*ServerTest) RegisterHandler

func (ts *ServerTest) RegisterHandler(path string, handler handler)

type TokenRoundTripper added in v1.10.0

type TokenRoundTripper struct {
	Token    string
	Fallback http.RoundTripper
}

TokenRoundTripper is a struct that implements the RoundTripper interface, specifically to handle the authentication token by adding a token to the request header. We need this because the API requires that each request include a valid API token in the headers for authentication and authorization.

func (*TokenRoundTripper) RoundTrip added in v1.10.0

func (t *TokenRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip takes an *http.Request as input and returns an *http.Response and an error.

It is expected to use the provided request to create a connection to an HTTP server and return the response, or an error if one occurred. The returned Response should have its Body closed. If the RoundTrip method returns an error, the Client's Get, Head, Post, and PostForm methods return the same error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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