test

package
v1.17.5-vision-2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func CreateTestDirectory

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

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

func CreateTestFile

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

type FailingErrorBuffer struct{}

func (*FailingErrorBuffer) Bytes

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

func (*FailingErrorBuffer) Len

func (b *FailingErrorBuffer) Len() int

func (*FailingErrorBuffer) Write

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

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

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