Documentation
¶
Overview ¶
Package testutil provides testing utilities for the Opik SDK. This mirrors the Python SDK's testlib package.
Index ¶
- func AssertFloatNear(t *testing.T, expected, actual, tolerance float64)
- func AssertJSONEqual(t *testing.T, expected, actual any)
- func AssertMapHasKeys(t *testing.T, m map[string]any, keys ...string)
- func AssertMatch(t *testing.T, matcher Matcher, value any)
- type AnyButNilMatcher
- type AnyFloatMatcher
- type AnyMapMatcher
- type AnyMatcher
- type AnySliceMatcher
- type AnyStringMatcher
- func (m *AnyStringMatcher) Containing(substr string) *AnyStringMatcher
- func (m AnyStringMatcher) Match(value any) bool
- func (m AnyStringMatcher) String() string
- func (m *AnyStringMatcher) WithPrefix(prefix string) *AnyStringMatcher
- func (m *AnyStringMatcher) WithSuffix(suffix string) *AnyStringMatcher
- type Matcher
- type MockEnv
- type MockServer
- func (ms *MockServer) Close()
- func (ms *MockServer) LastRequest() *RecordedRequest
- func (ms *MockServer) On(method, path string) *Route
- func (ms *MockServer) OnDelete(path string) *Route
- func (ms *MockServer) OnGet(path string) *Route
- func (ms *MockServer) OnPatch(path string) *Route
- func (ms *MockServer) OnPost(path string) *Route
- func (ms *MockServer) OnPut(path string) *Route
- func (ms *MockServer) RequestCount() int
- func (ms *MockServer) Requests() []*RecordedRequest
- func (ms *MockServer) RequestsForPath(path string) []*RecordedRequest
- func (ms *MockServer) Reset()
- func (ms *MockServer) RouteCallCount(method, path string) int
- func (ms *MockServer) URL() string
- type RecordedRequest
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFloatNear ¶
AssertFloatNear checks if two floats are within tolerance.
func AssertJSONEqual ¶
AssertJSONEqual compares two values as JSON.
func AssertMapHasKeys ¶
AssertMapHasKeys checks if a map has all required keys.
Types ¶
type AnyButNilMatcher ¶
type AnyButNilMatcher struct{}
AnyButNilMatcher matches any non-nil value.
func (AnyButNilMatcher) Match ¶
func (m AnyButNilMatcher) Match(value any) bool
func (AnyButNilMatcher) String ¶
func (m AnyButNilMatcher) String() string
type AnyFloatMatcher ¶
AnyFloatMatcher matches floats within a range or tolerance.
func (*AnyFloatMatcher) Between ¶
func (m *AnyFloatMatcher) Between(min, max float64) *AnyFloatMatcher
Between sets min/max range.
func (AnyFloatMatcher) Match ¶
func (m AnyFloatMatcher) Match(value any) bool
func (*AnyFloatMatcher) Near ¶
func (m *AnyFloatMatcher) Near(expected, tolerance float64) *AnyFloatMatcher
Near sets expected value with tolerance.
func (AnyFloatMatcher) String ¶
func (m AnyFloatMatcher) String() string
type AnyMapMatcher ¶
type AnyMapMatcher struct {
RequiredKeys []string
}
AnyMapMatcher matches any map, optionally requiring specific keys.
func (AnyMapMatcher) Match ¶
func (m AnyMapMatcher) Match(value any) bool
func (AnyMapMatcher) String ¶
func (m AnyMapMatcher) String() string
type AnyMatcher ¶
type AnyMatcher struct{}
AnyMatcher matches any value including nil.
func (AnyMatcher) Match ¶
func (m AnyMatcher) Match(value any) bool
func (AnyMatcher) String ¶
func (m AnyMatcher) String() string
type AnySliceMatcher ¶
AnySliceMatcher matches any slice.
func (AnySliceMatcher) Match ¶
func (m AnySliceMatcher) Match(value any) bool
func (AnySliceMatcher) String ¶
func (m AnySliceMatcher) String() string
type AnyStringMatcher ¶
AnyStringMatcher matches any string, optionally with constraints.
func (*AnyStringMatcher) Containing ¶
func (m *AnyStringMatcher) Containing(substr string) *AnyStringMatcher
Containing adds a contains requirement.
func (AnyStringMatcher) Match ¶
func (m AnyStringMatcher) Match(value any) bool
func (AnyStringMatcher) String ¶
func (m AnyStringMatcher) String() string
func (*AnyStringMatcher) WithPrefix ¶
func (m *AnyStringMatcher) WithPrefix(prefix string) *AnyStringMatcher
WithPrefix adds a prefix requirement.
func (*AnyStringMatcher) WithSuffix ¶
func (m *AnyStringMatcher) WithSuffix(suffix string) *AnyStringMatcher
WithSuffix adds a suffix requirement.
type MockEnv ¶
type MockEnv struct {
// contains filtered or unexported fields
}
MockEnv temporarily sets environment variables for a test.
func NewMockEnv ¶
NewMockEnv creates a new environment mocker.
type MockServer ¶
MockServer provides an HTTP test server that records requests and returns configured responses. This is similar to Python's respx library.
func (*MockServer) LastRequest ¶
func (ms *MockServer) LastRequest() *RecordedRequest
LastRequest returns the most recent request.
func (*MockServer) On ¶
func (ms *MockServer) On(method, path string) *Route
On registers a route for any method.
func (*MockServer) OnDelete ¶
func (ms *MockServer) OnDelete(path string) *Route
OnDelete registers a DELETE route.
func (*MockServer) OnGet ¶
func (ms *MockServer) OnGet(path string) *Route
OnGet registers a GET route.
func (*MockServer) OnPatch ¶
func (ms *MockServer) OnPatch(path string) *Route
OnPatch registers a PATCH route.
func (*MockServer) OnPost ¶
func (ms *MockServer) OnPost(path string) *Route
OnPost registers a POST route.
func (*MockServer) OnPut ¶
func (ms *MockServer) OnPut(path string) *Route
OnPut registers a PUT route.
func (*MockServer) RequestCount ¶
func (ms *MockServer) RequestCount() int
RequestCount returns the number of recorded requests.
func (*MockServer) Requests ¶
func (ms *MockServer) Requests() []*RecordedRequest
Requests returns all recorded requests.
func (*MockServer) RequestsForPath ¶
func (ms *MockServer) RequestsForPath(path string) []*RecordedRequest
RequestsForPath returns requests matching a specific path.
func (*MockServer) RouteCallCount ¶
func (ms *MockServer) RouteCallCount(method, path string) int
RouteCallCount returns how many times a route was called.
type RecordedRequest ¶
RecordedRequest captures details of an incoming request.
type Route ¶
type Route struct {
Method string
Path string
StatusCode int
Response any
Headers map[string]string
Handler http.HandlerFunc
CallCount int
}
Route defines a mock route with its response.
func (*Route) RespondJSON ¶
RespondJSON sets a JSON response.
func (*Route) WithHandler ¶
func (r *Route) WithHandler(handler http.HandlerFunc) *Route
WithHandler sets a custom handler.