Documentation
¶
Index ¶
- func FakeHTTP(handler http.Handler) *httptest.Server
- func UnfreezeTime()
- func WithoutExceptionHandling(fn func())
- type ArtisanTestCase
- func (atc *ArtisanTestCase) Args(args ...string) *ArtisanTestCase
- func (atc *ArtisanTestCase) AssertExitCode(code int) *ArtisanTestCase
- func (atc *ArtisanTestCase) AssertOutputContains(str string) *ArtisanTestCase
- func (atc *ArtisanTestCase) AssertOutputIs(expected string) *ArtisanTestCase
- func (atc *ArtisanTestCase) AssertOutputNotContains(str string) *ArtisanTestCase
- func (atc *ArtisanTestCase) AssertSuccessful() *ArtisanTestCase
- func (atc *ArtisanTestCase) Output() string
- type ConcurrentTestCase
- type DBTestContext
- func (c *DBTestContext) GetTransaction() *sql.Tx
- func (c *DBTestContext) RefreshDatabase(t *testing.T, testFunc func())
- func (c *DBTestContext) SetupSuite()
- func (c *DBTestContext) UseInMemorySQLite(t *testing.T, testFunc func(db *sql.DB))
- func (c *DBTestContext) WithTransaction(t *testing.T, fn func(tx *sql.Tx))
- type FakeClock
- type FakeHandler
- func (h *FakeHandler) AssertMethod(method string) bool
- func (h *FakeHandler) AssertSent(url string) bool
- func (h *FakeHandler) LastRequest() *http.Request
- func (h *FakeHandler) Queue(responses ...FakeResponse)
- func (h *FakeHandler) RequestCount() int
- func (h *FakeHandler) Reset()
- func (h *FakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type FakeResponse
- type Mock
- func (m *Mock) Call(method string, args ...any) []any
- func (m *Mock) CallHistory() []MockCall
- func (m *Mock) CalledTimes(method string) int
- func (m *Mock) CalledWith(method string, args ...any) bool
- func (m *Mock) LastCall(method string) *MockCall
- func (m *Mock) Reset()
- func (m *Mock) Stub(method string, returns ...any) *Mock
- func (m *Mock) WasCalled(method string) bool
- type MockCall
- type MockStub
- type ParallelTestCase
- type Spy
- type TestCase
- func (tc *TestCase) ActingAs(user any) *TestCase
- func (tc *TestCase) AssertDatabaseCount(table string, expected int)
- func (tc *TestCase) AssertDatabaseHas(table string, conditions map[string]any)
- func (tc *TestCase) AssertDatabaseHasColumns(table string, columns ...string)
- func (tc *TestCase) AssertDatabaseHasExactly(table string, conditions map[string]any)
- func (tc *TestCase) AssertDatabaseHasNoRecords(table string)
- func (tc *TestCase) AssertDatabaseMissing(table string, conditions map[string]any)
- func (tc *TestCase) AssertDatabaseTable(table string)
- func (tc *TestCase) AssertNotSoftDeleted(table string, conditions map[string]any)
- func (tc *TestCase) AssertSoftDeleted(table string, conditions map[string]any)
- func (tc *TestCase) Get(uri string) *TestResponse
- func (tc *TestCase) Post(uri string, body io.Reader) *TestResponse
- func (tc *TestCase) Upload(url, fieldName, filename, content string) *TestResponse
- type TestResponse
- func (tr *TestResponse) AssertClientError() *TestResponse
- func (tr *TestResponse) AssertCookie(name string) *TestResponse
- func (tr *TestResponse) AssertCookieExists(name string) *TestResponse
- func (tr *TestResponse) AssertCookieExpired(name string) *TestResponse
- func (tr *TestResponse) AssertCookieNotExpired(name string) *TestResponse
- func (tr *TestResponse) AssertCookieValue(name, value string) *TestResponse
- func (tr *TestResponse) AssertCreated() *TestResponse
- func (tr *TestResponse) AssertDontSee(text string) *TestResponse
- func (tr *TestResponse) AssertDontSeeHtml(html string) *TestResponse
- func (tr *TestResponse) AssertDownload(filename string) *TestResponse
- func (tr *TestResponse) AssertExactJson(data map[string]any) *TestResponse
- func (tr *TestResponse) AssertForbidden() *TestResponse
- func (tr *TestResponse) AssertHeader(key, value string) *TestResponse
- func (tr *TestResponse) AssertHeaderContains(name, value string) *TestResponse
- func (tr *TestResponse) AssertIsRedirect() *TestResponse
- func (tr *TestResponse) AssertJson(key string, value any) *TestResponse
- func (tr *TestResponse) AssertJsonCount(key string, count int) *TestResponse
- func (tr *TestResponse) AssertJsonMap(expected map[string]any) *TestResponse
- func (tr *TestResponse) AssertJsonStructure(keys ...string) *TestResponse
- func (tr *TestResponse) AssertJsonValidationErrors(fields ...string) *TestResponse
- func (tr *TestResponse) AssertNotFound() *TestResponse
- func (tr *TestResponse) AssertOk() *TestResponse
- func (tr *TestResponse) AssertRedirect(url string) *TestResponse
- func (tr *TestResponse) AssertRedirectToRoute(route string, params ...any) *TestResponse
- func (tr *TestResponse) AssertSee(text string) *TestResponse
- func (tr *TestResponse) AssertSeeHtml(html string) *TestResponse
- func (tr *TestResponse) AssertSeeText(text string) *TestResponse
- func (tr *TestResponse) AssertServerError() *TestResponse
- func (tr *TestResponse) AssertStatus(code int) *TestResponse
- func (tr *TestResponse) AssertStreamed() *TestResponse
- func (tr *TestResponse) AssertSuccessful() *TestResponse
- func (tr *TestResponse) AssertUnauthorized() *TestResponse
- func (tr *TestResponse) AssertUnprocessableEntity() *TestResponse
- func (tr *TestResponse) AssertViewHas(key string) *TestResponse
- func (tr *TestResponse) AssertViewHasValue(key string, value string) *TestResponse
- func (tr *TestResponse) AssertViewIs(view string) *TestResponse
- type TestResult
- type TimeTravel
- func (t *TimeTravel) Add(d time.Duration)
- func (t *TimeTravel) Freeze()
- func (t *TimeTravel) IsFrozen() bool
- func (t *TimeTravel) Now() time.Time
- func (t *TimeTravel) SetNow(now time.Time)
- func (t *TimeTravel) Since(then time.Time) time.Duration
- func (t *TimeTravel) Sub(other time.Time) time.Duration
- func (t *TimeTravel) Travel(d time.Duration)
- func (t *TimeTravel) TravelToDate(year int, month time.Month, day, hour, min, sec int)
- func (t *TimeTravel) Unfreeze()
- func (t *TimeTravel) Until(then time.Time) time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithoutExceptionHandling ¶
func WithoutExceptionHandling(fn func())
WithoutExceptionHandling runs the given function with exception handling disabled.
Types ¶
type ArtisanTestCase ¶
ArtisanTestCase provides testing utilities for artisan commands.
func NewArtisanTestCase ¶
func NewArtisanTestCase(t *testing.T, args ...string) *ArtisanTestCase
NewArtisanTestCase creates a new artisan test case.
func (*ArtisanTestCase) Args ¶
func (atc *ArtisanTestCase) Args(args ...string) *ArtisanTestCase
Args sets the command arguments.
func (*ArtisanTestCase) AssertExitCode ¶
func (atc *ArtisanTestCase) AssertExitCode(code int) *ArtisanTestCase
AssertExitCode asserts the command exited with the given code.
func (*ArtisanTestCase) AssertOutputContains ¶
func (atc *ArtisanTestCase) AssertOutputContains(str string) *ArtisanTestCase
AssertOutputContains asserts the output contains the given string.
func (*ArtisanTestCase) AssertOutputIs ¶
func (atc *ArtisanTestCase) AssertOutputIs(expected string) *ArtisanTestCase
AssertOutputIs asserts the output is exactly the given string.
func (*ArtisanTestCase) AssertOutputNotContains ¶
func (atc *ArtisanTestCase) AssertOutputNotContains(str string) *ArtisanTestCase
AssertOutputNotContains asserts the output does not contain the given string.
func (*ArtisanTestCase) AssertSuccessful ¶
func (atc *ArtisanTestCase) AssertSuccessful() *ArtisanTestCase
AssertSuccessful asserts the command was successful (exit code 0).
func (*ArtisanTestCase) Output ¶
func (atc *ArtisanTestCase) Output() string
Output returns the command output.
type ConcurrentTestCase ¶
ConcurrentTestCase manages concurrent test execution with shared state.
func NewConcurrentTestCase ¶
NewConcurrentTestCase creates a new concurrent test case.
func (*ConcurrentTestCase) AssertNoErrors ¶
func (ctc *ConcurrentTestCase) AssertNoErrors()
AssertNoErrors asserts that no errors occurred in the error channel.
func (*ConcurrentTestCase) Run ¶
func (ctc *ConcurrentTestCase) Run(workers int, fn func(workerID int) error)
Run runs a function concurrently with the specified number of workers.
func (*ConcurrentTestCase) RunWithTimeout ¶
func (ctc *ConcurrentTestCase) RunWithTimeout(timeout time.Duration, fn func() error)
RunWithTimeout runs a function with a timeout.
type DBTestContext ¶
type DBTestContext struct {
// contains filtered or unexported fields
}
DBTestContext manages database state for tests.
func NewDBTestContext ¶
func NewDBTestContext(db *sql.DB) *DBTestContext
NewDBTestContext initializes a new database testing context.
func (*DBTestContext) GetTransaction ¶
func (c *DBTestContext) GetTransaction() *sql.Tx
GetTransaction returns the current transaction (if RefreshDatabase was used).
func (*DBTestContext) RefreshDatabase ¶
func (c *DBTestContext) RefreshDatabase(t *testing.T, testFunc func())
RefreshDatabase wraps a test in a transaction and automatically rolls it back after the test. This is the recommended way to keep tests isolated and fast.
func (*DBTestContext) SetupSuite ¶
func (c *DBTestContext) SetupSuite()
SetupSuite should be called once before all tests run. It applies all migrations to the database.
func (*DBTestContext) UseInMemorySQLite ¶
func (c *DBTestContext) UseInMemorySQLite(t *testing.T, testFunc func(db *sql.DB))
UseInMemorySQLite sets up a completely fresh SQLite database in memory for the test.
func (*DBTestContext) WithTransaction ¶
func (c *DBTestContext) WithTransaction(t *testing.T, fn func(tx *sql.Tx))
WithTransaction is a helper that lets you run a block inside a transaction. Useful when you want to share the same transaction across multiple operations in a test.
type FakeClock ¶
type FakeClock struct {
// contains filtered or unexported fields
}
FakeClock provides time control for testing.
func NewFakeClock ¶
func NewFakeClock() *FakeClock
NewFakeClock creates a new FakeClock at the current time.
type FakeHandler ¶
type FakeHandler struct {
Requests []*http.Request
Responses []FakeResponse
// contains filtered or unexported fields
}
FakeHandler records HTTP requests for testing.
func FakeHTTPHandler ¶
func FakeHTTPHandler() (*FakeHandler, http.Handler)
FakeHTTPHandler returns a handler that records requests.
func (*FakeHandler) AssertMethod ¶
func (h *FakeHandler) AssertMethod(method string) bool
AssertMethod asserts that a specific HTTP method was used.
func (*FakeHandler) AssertSent ¶
func (h *FakeHandler) AssertSent(url string) bool
AssertSent asserts that a request was sent to a specific URL.
func (*FakeHandler) LastRequest ¶
func (h *FakeHandler) LastRequest() *http.Request
LastRequest returns the last recorded request.
func (*FakeHandler) Queue ¶
func (h *FakeHandler) Queue(responses ...FakeResponse)
Queue records requests made to the fake handler.
func (*FakeHandler) RequestCount ¶
func (h *FakeHandler) RequestCount() int
RequestCount returns the number of requests made.
func (*FakeHandler) Reset ¶
func (h *FakeHandler) Reset()
Reset clears all recorded requests and responses.
func (*FakeHandler) ServeHTTP ¶
func (h *FakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP records the request and returns a configured response.
type FakeResponse ¶
FakeResponse represents a pre-configured response.
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock provides a simple mock framework for testing.
func (*Mock) CallHistory ¶
CallHistory returns all recorded calls.
func (*Mock) CalledTimes ¶
CalledTimes returns the number of times a method was called.
func (*Mock) CalledWith ¶
CalledWith checks if a method was called with specific arguments.
type MockStub ¶
type MockStub struct {
Returns []any
}
MockStub represents a stubbed method return value.
type ParallelTestCase ¶
ParallelTestCase provides parallel test execution support.
func NewParallelTestCase ¶
func NewParallelTestCase(t *testing.T, workers int) *ParallelTestCase
NewParallelTestCase creates a new parallel test case.
func (*ParallelTestCase) Run ¶
func (ptc *ParallelTestCase) Run(fn func(workerID int))
Run runs the given function in parallel with multiple workers.
func (*ParallelTestCase) RunParallel ¶
func (ptc *ParallelTestCase) RunParallel(fns ...func(workerID int))
RunParallel runs multiple test functions in parallel.
type Spy ¶
type Spy struct {
*Mock
// contains filtered or unexported fields
}
Spy wraps a real implementation and records calls.
type TestCase ¶
type TestCase struct {
*testing.T
App *foundation.Application
DB *orm.DB
Router *routing.Router
// contains filtered or unexported fields
}
TestCase provides a fluent testing API similar to Laravel.
func NewTestCase ¶
func NewTestCase(t *testing.T, app *foundation.Application, db *orm.DB, router *routing.Router) *TestCase
NewTestCase initializes a test environment.
func (*TestCase) AssertDatabaseCount ¶
AssertDatabaseCount asserts that a table has exactly `expected` number of rows.
func (*TestCase) AssertDatabaseHas ¶
AssertDatabaseHas asserts that a database table contains a row matching the given constraints.
func (*TestCase) AssertDatabaseHasColumns ¶
AssertDatabaseHasColumns asserts that a table has the given columns.
func (*TestCase) AssertDatabaseHasExactly ¶
AssertDatabaseHasExactly asserts that a table contains **exactly one** row matching the conditions.
func (*TestCase) AssertDatabaseHasNoRecords ¶
AssertDatabaseHasNoRecords asserts that a table is completely empty.
func (*TestCase) AssertDatabaseMissing ¶
AssertDatabaseMissing asserts that a database table does NOT contain a row matching the given constraints.
func (*TestCase) AssertDatabaseTable ¶
AssertDatabaseTable asserts that a database table exists.
func (*TestCase) AssertNotSoftDeleted ¶
AssertNotSoftDeleted asserts that a row has NOT been soft-deleted.
func (*TestCase) AssertSoftDeleted ¶
AssertSoftDeleted asserts that a row has been soft-deleted (deleted_at is not null).
func (*TestCase) Get ¶
func (tc *TestCase) Get(uri string) *TestResponse
Get dispatch a GET request to the application.
func (*TestCase) Post ¶
func (tc *TestCase) Post(uri string, body io.Reader) *TestResponse
Post dispatch a POST request to the application.
func (*TestCase) Upload ¶
func (tc *TestCase) Upload(url, fieldName, filename, content string) *TestResponse
Upload simulates a file upload (multipart).
type TestResponse ¶
type TestResponse struct {
T *testing.T
Recorder *httptest.ResponseRecorder
}
TestResponse wraps the httptest.ResponseRecorder for fluent assertions.
func (*TestResponse) AssertClientError ¶
func (tr *TestResponse) AssertClientError() *TestResponse
AssertClientError asserts the response status is 4xx.
func (*TestResponse) AssertCookie ¶
func (tr *TestResponse) AssertCookie(name string) *TestResponse
AssertCookie asserts the response contains a cookie with the given name.
func (*TestResponse) AssertCookieExists ¶
func (tr *TestResponse) AssertCookieExists(name string) *TestResponse
AssertCookieExists asserts a cookie exists
func (*TestResponse) AssertCookieExpired ¶
func (tr *TestResponse) AssertCookieExpired(name string) *TestResponse
AssertCookieExpired asserts a cookie is expired
func (*TestResponse) AssertCookieNotExpired ¶
func (tr *TestResponse) AssertCookieNotExpired(name string) *TestResponse
AssertCookieNotExpired asserts a cookie is not expired
func (*TestResponse) AssertCookieValue ¶
func (tr *TestResponse) AssertCookieValue(name, value string) *TestResponse
AssertCookieValue asserts the response contains a cookie with the given value.
func (*TestResponse) AssertCreated ¶
func (tr *TestResponse) AssertCreated() *TestResponse
AssertCreated asserts a 201 status
func (*TestResponse) AssertDontSee ¶
func (tr *TestResponse) AssertDontSee(text string) *TestResponse
AssertDontSee asserts the response body does NOT contain the given text.
func (*TestResponse) AssertDontSeeHtml ¶
func (tr *TestResponse) AssertDontSeeHtml(html string) *TestResponse
AssertDontSeeHtml asserts the response doesn't contain HTML
func (*TestResponse) AssertDownload ¶
func (tr *TestResponse) AssertDownload(filename string) *TestResponse
AssertDownload asserts the response is a file download
func (*TestResponse) AssertExactJson ¶
func (tr *TestResponse) AssertExactJson(data map[string]any) *TestResponse
AssertExactJson asserts the response contains exact JSON
func (*TestResponse) AssertForbidden ¶
func (tr *TestResponse) AssertForbidden() *TestResponse
AssertForbidden asserts a 403 status
func (*TestResponse) AssertHeader ¶
func (tr *TestResponse) AssertHeader(key, value string) *TestResponse
AssertHeader asserts the response contains a specific header value.
func (*TestResponse) AssertHeaderContains ¶
func (tr *TestResponse) AssertHeaderContains(name, value string) *TestResponse
AssertHeaderContains asserts a header contains a value
func (*TestResponse) AssertIsRedirect ¶
func (tr *TestResponse) AssertIsRedirect() *TestResponse
AssertIsRedirect asserts a 3xx redirect
func (*TestResponse) AssertJson ¶
func (tr *TestResponse) AssertJson(key string, value any) *TestResponse
AssertJson asserts the response contains the given JSON key/value.
func (*TestResponse) AssertJsonCount ¶
func (tr *TestResponse) AssertJsonCount(key string, count int) *TestResponse
AssertJsonCount asserts the response JSON array has the given count.
func (*TestResponse) AssertJsonMap ¶
func (tr *TestResponse) AssertJsonMap(expected map[string]any) *TestResponse
AssertJsonMap asserts the response JSON matches the given map.
func (*TestResponse) AssertJsonStructure ¶
func (tr *TestResponse) AssertJsonStructure(keys ...string) *TestResponse
AssertJsonStructure asserts top-level keys exist.
func (*TestResponse) AssertJsonValidationErrors ¶
func (tr *TestResponse) AssertJsonValidationErrors(fields ...string) *TestResponse
AssertJsonValidationErrors asserts JSON validation errors for fields
func (*TestResponse) AssertNotFound ¶
func (tr *TestResponse) AssertNotFound() *TestResponse
AssertNotFound asserts a 404 status
func (*TestResponse) AssertOk ¶
func (tr *TestResponse) AssertOk() *TestResponse
AssertOk asserts the response status is 200 OK.
func (*TestResponse) AssertRedirect ¶
func (tr *TestResponse) AssertRedirect(url string) *TestResponse
AssertRedirect asserts a redirect response
func (*TestResponse) AssertRedirectToRoute ¶
func (tr *TestResponse) AssertRedirectToRoute(route string, params ...any) *TestResponse
AssertRedirectToRoute asserts a redirect to a named route
func (*TestResponse) AssertSee ¶
func (tr *TestResponse) AssertSee(text string) *TestResponse
AssertSee asserts the response body contains the given text.
func (*TestResponse) AssertSeeHtml ¶
func (tr *TestResponse) AssertSeeHtml(html string) *TestResponse
AssertSeeHtml asserts the response contains HTML
func (*TestResponse) AssertSeeText ¶
func (tr *TestResponse) AssertSeeText(text string) *TestResponse
AssertSeeText asserts the response body contains the given text (as plain text).
func (*TestResponse) AssertServerError ¶
func (tr *TestResponse) AssertServerError() *TestResponse
AssertServerError asserts the response status is 5xx.
func (*TestResponse) AssertStatus ¶
func (tr *TestResponse) AssertStatus(code int) *TestResponse
AssertStatus asserts the response HTTP status code.
func (*TestResponse) AssertStreamed ¶
func (tr *TestResponse) AssertStreamed() *TestResponse
AssertStreamed asserts the response is streamed
func (*TestResponse) AssertSuccessful ¶
func (tr *TestResponse) AssertSuccessful() *TestResponse
AssertSuccessful asserts the response status is 2xx.
func (*TestResponse) AssertUnauthorized ¶
func (tr *TestResponse) AssertUnauthorized() *TestResponse
AssertUnauthorized asserts a 401 status
func (*TestResponse) AssertUnprocessableEntity ¶
func (tr *TestResponse) AssertUnprocessableEntity() *TestResponse
AssertUnprocessableEntity asserts a 422 status
func (*TestResponse) AssertViewHas ¶
func (tr *TestResponse) AssertViewHas(key string) *TestResponse
AssertViewHas asserts the view data contains the given key.
func (*TestResponse) AssertViewHasValue ¶
func (tr *TestResponse) AssertViewHasValue(key string, value string) *TestResponse
AssertViewHasValue asserts the view data contains the given key with the expected value.
func (*TestResponse) AssertViewIs ¶
func (tr *TestResponse) AssertViewIs(view string) *TestResponse
AssertViewIs asserts the response was rendered with the given view name.
type TestResult ¶
TestResult represents the result of a concurrent test.
type TimeTravel ¶
type TimeTravel struct {
// contains filtered or unexported fields
}
TimeTravel provides time manipulation for testing.
func GetTimeTravel ¶
func GetTimeTravel() *TimeTravel
GetTimeTravel returns the global TimeTravel instance.
func NewTimeTravel ¶
func NewTimeTravel() *TimeTravel
NewTimeTravel creates a new TimeTravel instance.
func TravelTime ¶
func TravelTime(d time.Duration) *TimeTravel
TravelTime travels by the given duration using the global time.
func (*TimeTravel) Add ¶
func (t *TimeTravel) Add(d time.Duration)
Add adds duration to the current fake time.
func (*TimeTravel) IsFrozen ¶
func (t *TimeTravel) IsFrozen() bool
IsFrozen returns whether time travel is active.
func (*TimeTravel) SetNow ¶
func (t *TimeTravel) SetNow(now time.Time)
SetNow sets the current fake time.
func (*TimeTravel) Since ¶
func (t *TimeTravel) Since(then time.Time) time.Duration
Since returns the duration since the given time (using fake time).
func (*TimeTravel) Sub ¶
func (t *TimeTravel) Sub(other time.Time) time.Duration
Sub returns the difference between two fake times.
func (*TimeTravel) Travel ¶
func (t *TimeTravel) Travel(d time.Duration)
Travel moves the fake time by the given duration.
func (*TimeTravel) TravelToDate ¶
func (t *TimeTravel) TravelToDate(year int, month time.Month, day, hour, min, sec int)
TravelToDate moves the fake time to a specific date.
func (*TimeTravel) Unfreeze ¶
func (t *TimeTravel) Unfreeze()
Unfreeze stops time travel and returns to real time.