Documentation
¶
Overview ¶
Package testutil provides test utilities, fixtures, and helpers for SCRIBE tests.
Index ¶
- func AssertBodyContains(t *testing.T, resp *httptest.ResponseRecorder, substring string)
- func AssertContentType(t *testing.T, resp *httptest.ResponseRecorder, expected string)
- func AssertError(t *testing.T, err error)
- func AssertJSONArrayResponse(t *testing.T, resp *httptest.ResponseRecorder) []any
- func AssertJSONField(t *testing.T, data map[string]any, field string, expected any)
- func AssertJSONResponse(t *testing.T, resp *httptest.ResponseRecorder) map[string]any
- func AssertNoError(t *testing.T, err error)
- func AssertStatusCode(t *testing.T, resp *httptest.ResponseRecorder, expected int)
- func CleanupTestDB(t *testing.T, db *sqlite.Database)
- func GetLogCount(t *testing.T, db *sqlite.Database) int
- func MakeJSONRequest(t *testing.T, method, url string, data any) *http.Request
- func MakeRequest(method, url string, body io.Reader) *http.Request
- func NewTestLog() *entities.Log
- func NewTestLogBatch(count int) []*entities.Log
- func NewTestLogMinimal() *entities.Log
- func NewTestLogWithBody(body map[string]any) *entities.Log
- func NewTestLogWithOptions(opts TestLogOptions) *entities.Log
- func NewTestLogWithSeverity(severity valueobjects.Severity) *entities.Log
- func NewTestLogWithTitle(title string) *entities.Log
- func SetupTestDB(t *testing.T) *sqlite.Database
- func TruncateLogs(t *testing.T, db *sqlite.Database)
- type TestLogOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertBodyContains ¶
func AssertBodyContains(t *testing.T, resp *httptest.ResponseRecorder, substring string)
AssertBodyContains checks that the response body contains a string.
func AssertContentType ¶
func AssertContentType(t *testing.T, resp *httptest.ResponseRecorder, expected string)
AssertContentType checks that the response has the expected content type.
func AssertError ¶
AssertError checks that an error is not nil.
func AssertJSONArrayResponse ¶
func AssertJSONArrayResponse(t *testing.T, resp *httptest.ResponseRecorder) []any
AssertJSONArrayResponse checks that the response is a valid JSON array.
func AssertJSONField ¶
AssertJSONField checks that a JSON response has a field with expected value.
func AssertJSONResponse ¶
AssertJSONResponse checks that the response is valid JSON.
func AssertNoError ¶
AssertNoError checks that an error is nil.
func AssertStatusCode ¶
func AssertStatusCode(t *testing.T, resp *httptest.ResponseRecorder, expected int)
AssertStatusCode checks that the response has the expected status code.
func CleanupTestDB ¶
CleanupTestDB closes and cleans up the test database.
func GetLogCount ¶
GetLogCount returns the number of logs in the database.
func MakeJSONRequest ¶
MakeJSONRequest creates an HTTP request with JSON body.
func MakeRequest ¶
MakeRequest creates an HTTP request for testing.
func NewTestLog ¶
NewTestLog creates a test log with sensible defaults.
func NewTestLogBatch ¶
NewTestLogBatch creates multiple test logs.
func NewTestLogMinimal ¶
NewTestLogMinimal creates a minimal valid log (only required fields).
func NewTestLogWithBody ¶
NewTestLogWithBody creates a test log with specific body.
func NewTestLogWithOptions ¶
func NewTestLogWithOptions(opts TestLogOptions) *entities.Log
NewTestLogWithOptions creates a test log with custom options.
func NewTestLogWithSeverity ¶
func NewTestLogWithSeverity(severity valueobjects.Severity) *entities.Log
NewTestLogWithSeverity creates a test log with specific severity.
func NewTestLogWithTitle ¶
NewTestLogWithTitle creates a test log with specific title.
func SetupTestDB ¶
SetupTestDB creates an in-memory SQLite database for testing.
Types ¶
type TestLogOptions ¶
type TestLogOptions struct {
Severity valueobjects.Severity
Title string
Description string
Source string
Color valueobjects.Color
Body map[string]any
}
TestLogOptions allows customization of test logs.