{"modulePath":"github.com/JAD-RAD/aurabase","version":"v0.0.0-20241105172544-18993a5c1f85","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package tests\n\nPackage tests provides common helpers and mocks used in PocketBase application tests.\n\n## Functions\n\n```go\nfunc MockLogsData(app *TestApp) error\n```\n\n```go\nfunc MockMultipartData(data map[string]string, fileFields ...string) (*bytes.Buffer, *multipart.Writer, error)\n```\nMockMultipartData creates a mocked multipart/form-data payload.\n\nExample\n\n\tdata, mp, err := tests.MockMultipartData(\n\t\tmap[string]string{\"title\": \"new\"},\n\t\t\"file1\",\n\t\t\"file2\",\n\t\t...\n\t)\n\n```go\nfunc TempDirClone(dirToClone string) (string, error)\n```\nTempDirClone creates a new temporary directory copy from the provided directory path.\n\nIt is the caller's responsibility to call \\`os.RemoveAll(tempDir)\\` when the directory is no longer needed!\n\n## Types\n\n```go\ntype ApiScenario struct {\n\tName           string\n\tMethod         string\n\tUrl            string\n\tBody           io.Reader\n\tRequestHeaders map[string]string\n\n\t// Delay adds a delay before checking the expectations usually\n\t// to ensure that all fired non-awaited go routines have finished\n\tDelay time.Duration\n\n\t// Timeout specifies how long to wait before cancelling the request context.\n\t//\n\t// A zero or negative value means that there will be no timeout.\n\tTimeout time.Duration\n\n\t// expectations\n\t// ---\n\tExpectedStatus     int\n\tExpectedContent    []string\n\tNotExpectedContent []string\n\tExpectedEvents     map[string]int\n\n\t// test hooks\n\t// ---\n\tTestAppFactory func(t *testing.T) *TestApp\n\tBeforeTestFunc func(t *testing.T, app *TestApp, e *echo.Echo)\n\tAfterTestFunc  func(t *testing.T, app *TestApp, res *http.Response)\n}\n```\nApiScenario defines a single api request test case/scenario.\n\n```go\nfunc (scenario *ApiScenario) Test(t *testing.T)\n```\nTest executes the test scenario.\n\n```go\ntype TestApp struct {\n\t*core.BaseApp\n\n\t// EventCalls defines a map to inspect which app events\n\t// (and how many times) were triggered.\n\t//\n\t// The following events are not counted because they execute always:\n\t// - OnBeforeBootstrap\n\t// - OnAfterBootstrap\n\t// - OnBeforeServe\n\tEventCalls map[string]int\n\n\tTestMailer *TestMailer\n\t// contains filtered or unexported fields\n}\n```\nTestApp is a wrapper app instance used for testing.\n\n```go\nfunc NewTestApp(optTestDataDir ...string) (*TestApp, error)\n```\nNewTestApp creates and initializes a test application instance.\n\nIt is the caller's responsibility to call \\`app.Cleanup()\\` when the app is no longer needed.\n\n```go\nfunc (t *TestApp) Cleanup()\n```\nCleanup resets the test application state and removes the test app's dataDir from the filesystem.\n\nAfter this call, the app instance shouldn't be used anymore.\n\n```go\nfunc (t *TestApp) NewMailClient() mailer.Mailer\n```\nNewMailClient initializes (if not already) a test app mail client.\n\n```go\nfunc (t *TestApp) ResetEventCalls()\n```\nResetEventCalls resets the EventCalls counter.\n\n```go\ntype TestMailer struct {\n\tTotalSend   int\n\tLastMessage mailer.Message\n\n\t// @todo consider deprecating the above 2 fields?\n\tSentMessages []mailer.Message\n\t// contains filtered or unexported fields\n}\n```\nTestMailer is a mock \\`mailer.Mailer\\` implementation.\n\n```go\nfunc (tm *TestMailer) Reset()\n```\nReset clears any previously test collected data.\n\n```go\nfunc (tm *TestMailer) Send(m *mailer.Message) error\n```\nSend implements \\`mailer.Mailer\\` interface.\n\n","path":"github.com/JAD-RAD/aurabase/tests","name":"tests","synopsis":"Package tests provides common helpers and mocks used in PocketBase application tests.","isRedistributable":true}
