Documentation
¶
Index ¶
- Constants
- func Int64Ptr(i int64) *int64
- func IntPtr(i int) *int
- func LoadFixture(t *testing.T, name string) string
- func RetryOnAPIError(t *testing.T, maxRetries int, operation func() error, operationName string)
- func StringPtr(s string) *string
- func TempDir(t *testing.T) string
- func TempFile(t *testing.T, name, content string) string
- func TestDB(t *testing.T) *state.DB
- func TryLoadFixture(name string) string
- type MockHTTPServer
- type MockResponse
- type MockRoundTripper
Constants ¶
const MaxAPIRetries = 3
MaxAPIRetries is the default number of retries for flaky external API calls
Variables ¶
This section is empty.
Functions ¶
func LoadFixture ¶
LoadFixture loads a test fixture file
func RetryOnAPIError ¶
RetryOnAPIError retries an operation when it encounters API-related errors This is useful for flaky external API integration tests (e.g., CivitAI, HuggingFace) Uses exponential backoff between retries (1s, 2s, 4s) Returns error if all retries fail with non-API errors, or skips test if API is unavailable
func TryLoadFixture ¶
TryLoadFixture attempts to load a fixture, returns empty string if not found
Types ¶
type MockHTTPServer ¶
type MockHTTPServer struct {
*httptest.Server
Responses map[string]MockResponse
}
MockHTTPServer creates a test HTTP server that serves canned responses from fixtures
func NewMockHTTPServer ¶
func NewMockHTTPServer() *MockHTTPServer
NewMockHTTPServer creates a new mock HTTP server
func (*MockHTTPServer) AddJSONResponse ¶
func (ms *MockHTTPServer) AddJSONResponse(path string, statusCode int, body string)
AddJSONResponse adds a JSON response for a specific path
func (*MockHTTPServer) AddResponse ¶
func (ms *MockHTTPServer) AddResponse(path string, response MockResponse)
AddResponse adds a canned response for a specific path
type MockResponse ¶
MockResponse represents a canned HTTP response
type MockRoundTripper ¶
MockRoundTripper implements http.RoundTripper for testing
func NewMockRoundTripper ¶
func NewMockRoundTripper() *MockRoundTripper
NewMockRoundTripper creates a new mock round tripper
func (*MockRoundTripper) AddStringResponse ¶
func (m *MockRoundTripper) AddStringResponse(url string, statusCode int, body string)
AddStringResponse adds a simple string response
func (*MockRoundTripper) AssertRequestMade ¶
func (m *MockRoundTripper) AssertRequestMade(t *testing.T, url string)
AssertRequestMade checks if a request was made to a specific URL