Documentation ¶
Overview ¶
Package test contains test helpers.
Index ¶
- Variables
- func CreateTestDirectory(t *testing.T) (path string, cleanup func())
- func CreateTestFile(t *testing.T, path string)
- func GetAPIKey(key string) (string, error)
- func GetTestToken() string
- func IsIntegrationTest() bool
- type ErrTestErrorAccumulatorWriteFailed
- type FailingErrorBuffer
- type Handler
- type ServerTest
- func (ts *ServerTest) ComposioTestServer() *httptest.Server
- func (ts *ServerTest) E2bTestServer() *httptest.Server
- func (ts *ServerTest) GroqTestServer() *httptest.Server
- func (ts *ServerTest) JigsawStackTestServer() *httptest.Server
- func (ts *ServerTest) RegisterHandler(path string, handler Handler)
- func (ts *ServerTest) ToolhouseTestServer() *httptest.Server
- type TokenRoundTripper
Constants ¶
This section is empty.
Variables ¶
var DefaultLogger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ AddSource: true, Level: slog.LevelDebug, ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr { if a.Key == "time" { return slog.Attr{} } if a.Key == "level" { return slog.Attr{} } if a.Key == slog.SourceKey { str := a.Value.String() split := strings.Split(str, "/") if len(split) > 2 { a.Value = slog.StringValue(strings.Join(split[len(split)-2:], "/")) a.Value = slog.StringValue(strings.Replace(a.Value.String(), "}", "", -1)) } } return a }}))
DefaultLogger is a default logger.
Functions ¶
func CreateTestDirectory ¶
CreateTestDirectory creates a temporary folder which will be deleted when cleanup is called.
func CreateTestFile ¶
CreateTestFile creates a fake file with "hello" as the content.
func IsIntegrationTest ¶ added in v0.9.4
func IsIntegrationTest() bool
IsIntegrationTest returns true if the unit test environment variable is set.
Types ¶
type ErrTestErrorAccumulatorWriteFailed ¶
type ErrTestErrorAccumulatorWriteFailed struct{}
ErrTestErrorAccumulatorWriteFailed is the error returned by the failing error buffer.
func (ErrTestErrorAccumulatorWriteFailed) Error ¶
func (e ErrTestErrorAccumulatorWriteFailed) Error() string
type FailingErrorBuffer ¶
type FailingErrorBuffer struct{}
FailingErrorBuffer is a buffer that always fails to write.
type Handler ¶
type Handler func(w http.ResponseWriter, r *http.Request)
Handler is a function that handles a request.
type ServerTest ¶
type ServerTest struct {
// contains filtered or unexported fields
}
ServerTest is a test server for the groq api.
func (*ServerTest) ComposioTestServer ¶
func (ts *ServerTest) ComposioTestServer() *httptest.Server
ComposioTestServer Creates a mocked Composer server which can pretend to handle requests during testing.
func (*ServerTest) E2bTestServer ¶
func (ts *ServerTest) E2bTestServer() *httptest.Server
E2bTestServer creates a test server for emulating the e2b api.
func (*ServerTest) GroqTestServer ¶
func (ts *ServerTest) GroqTestServer() *httptest.Server
GroqTestServer Creates a mocked Groq server which can pretend to handle requests during testing.
func (*ServerTest) JigsawStackTestServer ¶ added in v0.9.4
func (ts *ServerTest) JigsawStackTestServer() *httptest.Server
JigsawStackTestServer Creates a mocked JigsawStack server which can pretend to handle requests during testing.
func (*ServerTest) RegisterHandler ¶
func (ts *ServerTest) RegisterHandler(path string, handler Handler)
RegisterHandler registers a handler for a path.
func (*ServerTest) ToolhouseTestServer ¶
func (ts *ServerTest) ToolhouseTestServer() *httptest.Server
ToolhouseTestServer creates a test server for emulating the toolhouse api.
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 ¶
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.