testutils

package
v0.0.0-...-0c6c348 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFileEquals

func AssertFileEquals(t *testing.T, expectedFilePath, actualFilePath string)

func AssertFileEqualsString

func AssertFileEqualsString(t *testing.T, expectedFilePath, actual string)

func AssertValidationError

func AssertValidationError(t *testing.T, responseRecorder *httptest.ResponseRecorder, expectedErrorField string, expectedErrorMessage string)

func AssertValidationErrors

func AssertValidationErrors(t *testing.T, responseRecorder *httptest.ResponseRecorder, expectedErrors validation.ValidationError)

func BoolPtr

func BoolPtr(b bool) *bool

func CreateDeleteRequest

func CreateDeleteRequest(url string) *http.Request

func CreateGetRequest

func CreateGetRequest(t *testing.T, url string) *http.Request

func CreatePatchRequest

func CreatePatchRequest(t *testing.T, url string, payload interface{}) *http.Request

func CreatePostRequest

func CreatePostRequest(t *testing.T, url string, payload interface{}) *http.Request

func CreatePutRequest

func CreatePutRequest(t *testing.T, url string, payload interface{}) *http.Request

func DumpTable

func DumpTable(t *testing.T, db *dbutils.DBPool, tableName string)

DumpTable pretty-prints the contents of a database table for debugging purposes.

func GetProjectRoot

func GetProjectRoot() string

func Int64Ptr

func Int64Ptr(i int64) *int64

func IntPtr

func IntPtr(i int) *int

func NewRouter

func NewRouter() *chi.Mux

func SetupTestDB

func SetupTestDB(t *testing.T) *sql.DB

func StringPtr

func StringPtr(s string) *string

Types

type MockFileService

type MockFileService struct {
	UploadedFileName   string
	DownloadedFileName string
	DeletedFileNames   []string
	DownloadedFile     []byte
	UploadedFile       io.Reader
	UploadedLocation   string
}

func NewMockFileService

func NewMockFileService() *MockFileService

func (*MockFileService) DeleteFile

func (s *MockFileService) DeleteFile(fileName string) error

func (*MockFileService) DeleteFiles

func (s *MockFileService) DeleteFiles(fileNames []string) error

func (*MockFileService) DownloadFile

func (s *MockFileService) DownloadFile(fileName string) ([]byte, error)

func (*MockFileService) UploadFile

func (s *MockFileService) UploadFile(fileName string, file io.Reader) (string, error)

type Option

type Option func(options *options) error

func WithEmailTemplates

func WithEmailTemplates(emailTemplates *embed.FS) Option

type TestApp

type TestApp struct {
	*app.App
	TestRouter *chi.Mux
}

func NewTestApp

func NewTestApp(t *testing.T, opts ...Option) TestApp

func (*TestApp) MakeAuthenticatedDeleteRequest

func (a *TestApp) MakeAuthenticatedDeleteRequest(t *testing.T, path string) *httptest.ResponseRecorder

MakeAuthenticatedDeleteRequest issues a DELETE request to the given path with a default test user as the authenticated user. The caller is responsible for ensuring that the test user exists in the database.

func (*TestApp) MakeAuthenticatedGetRequest

func (a *TestApp) MakeAuthenticatedGetRequest(t *testing.T, path string) *httptest.ResponseRecorder

MakeAuthenticatedGetRequest issues a GET request to the given path with a default test user as the authenticated user. The caller is responsible for ensuring that the test user exists in the database.

func (*TestApp) MakeAuthenticatedPatchRequest

func (a *TestApp) MakeAuthenticatedPatchRequest(t *testing.T, path string, body interface{}) *httptest.ResponseRecorder

MakeAuthenticatedPatchRequest issues a PATCH request to the given path with a default test user as the authenticated user. The caller is responsible for ensuring that the test user exists in the database.

func (*TestApp) MakeAuthenticatedPostRequest

func (a *TestApp) MakeAuthenticatedPostRequest(t *testing.T, path string, body interface{}) *httptest.ResponseRecorder

MakeAuthenticatedPostRequest issues a POST request to the given path with a default test user as the authenticated user. The caller is responsible for ensuring that the test user exists in the database.

func (*TestApp) MakeAuthenticatedPutRequest

func (a *TestApp) MakeAuthenticatedPutRequest(t *testing.T, path string, body interface{}) *httptest.ResponseRecorder

MakeAuthenticatedPutRequest issues a PUT request to the given path with a default test user as the authenticated user. The caller is responsible for ensuring that the test user exists in the database.

func (*TestApp) MakeRequest

func (a *TestApp) MakeRequest(req *http.Request) *httptest.ResponseRecorder

type ValidationErrorResponse

type ValidationErrorResponse struct {
	Errors []validation.Error `json:"errors"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL