Documentation
¶
Overview ¶
Package testutil provides testing utilities and mock implementations.
Package testutil provides testing utilities and helpers.
Index ¶
- func MockProject(id, title, slug, ownerID string) *domain.Project
- func MockTask(id, title, projectID, reporterID string) *domain.Task
- func MockUser(id, email, username, name string) *domain.User
- func NewTestRouter() *gin.Engine
- func TestConfig() config.Config
- func TestContextWithUser(user *domain.User) context.Context
- func TestContextWithValue(key, value interface{}) context.Context
- type HTTPTestHelper
- func (h *HTTPTestHelper) AssertHeader(recorder *httptest.ResponseRecorder, header, expectedValue string)
- func (h *HTTPTestHelper) AssertJSON(recorder *httptest.ResponseRecorder, expected interface{})
- func (h *HTTPTestHelper) AssertStatus(recorder *httptest.ResponseRecorder, expectedStatus int)
- func (h *HTTPTestHelper) DELETE(url string, headers map[string]string) *httptest.ResponseRecorder
- func (h *HTTPTestHelper) GET(url string, headers map[string]string) *httptest.ResponseRecorder
- func (h *HTTPTestHelper) POST(url string, body interface{}, headers map[string]string) *httptest.ResponseRecorder
- func (h *HTTPTestHelper) PUT(url string, body interface{}, headers map[string]string) *httptest.ResponseRecorder
- func (h *HTTPTestHelper) Request(method, url string, body interface{}, headers map[string]string) *httptest.ResponseRecorder
- func (h *HTTPTestHelper) RunTestCases(testCases []TestCase)
- type MockProjectRepository
- func (m *MockProjectRepository) AddProject(project *domain.Project)
- func (m *MockProjectRepository) Count(_ context.Context) (int, error)
- func (m *MockProjectRepository) Create(_ context.Context, project *domain.Project) error
- func (m *MockProjectRepository) Delete(_ context.Context, id string) error
- func (m *MockProjectRepository) ExistsBySlug(_ context.Context, slug string) (bool, error)
- func (m *MockProjectRepository) GetByID(_ context.Context, id string) (*domain.Project, error)
- func (m *MockProjectRepository) GetBySlug(_ context.Context, slug string) (*domain.Project, error)
- func (m *MockProjectRepository) GetMemberProjects(_ context.Context, userID string, offset, limit int) ([]*domain.Project, error)
- func (m *MockProjectRepository) List(_ context.Context, offset, limit int) ([]*domain.Project, error)
- func (m *MockProjectRepository) ListByMember(_ context.Context, memberID string, offset, limit int) ([]*domain.Project, error)
- func (m *MockProjectRepository) ListByOwner(_ context.Context, ownerID string, offset, limit int) ([]*domain.Project, error)
- func (m *MockProjectRepository) Update(_ context.Context, project *domain.Project) error
- type MockTaskRepository
- func (m *MockTaskRepository) AddTask(task *domain.Task)
- func (m *MockTaskRepository) ArchiveTask(_ context.Context, id string) error
- func (m *MockTaskRepository) BulkDelete(_ context.Context, ids []string) error
- func (m *MockTaskRepository) BulkUpdate(_ context.Context, tasks []*domain.Task) error
- func (m *MockTaskRepository) BulkUpdateStatus(_ context.Context, taskIDs []string, newStatus domain.TaskStatus) error
- func (m *MockTaskRepository) Count(_ context.Context) (int, error)
- func (m *MockTaskRepository) CountByAssignee(_ context.Context, assigneeID string) (int, error)
- func (m *MockTaskRepository) CountByProject(_ context.Context, projectID string) (int, error)
- func (m *MockTaskRepository) CountByStatus(_ context.Context, status domain.TaskStatus) (int, error)
- func (m *MockTaskRepository) Create(_ context.Context, task *domain.Task) error
- func (m *MockTaskRepository) Delete(_ context.Context, id string) error
- func (m *MockTaskRepository) ExistsByID(_ context.Context, id string) (bool, error)
- func (m *MockTaskRepository) GetByID(_ context.Context, id string) (*domain.Task, error)
- func (m *MockTaskRepository) GetByProject(_ context.Context, projectID string, filters repository.TaskFilters) ([]*domain.Task, error)
- func (m *MockTaskRepository) GetDependencies(_ context.Context, taskID string) ([]*domain.Task, error)
- func (m *MockTaskRepository) GetSubtasks(_ context.Context, parentID string) ([]*domain.Task, error)
- func (m *MockTaskRepository) GetTasksByFilter(_ context.Context, filters repository.TaskFilters) ([]*domain.Task, error)
- func (m *MockTaskRepository) ListByAssignee(_ context.Context, assigneeID string, offset, limit int) ([]*domain.Task, error)
- func (m *MockTaskRepository) ListByCreator(_ context.Context, creatorID string, offset, limit int) ([]*domain.Task, error)
- func (m *MockTaskRepository) ListByProject(_ context.Context, projectID string, offset, limit int) ([]*domain.Task, error)
- func (m *MockTaskRepository) ListByStatus(_ context.Context, status domain.TaskStatus, offset, limit int) ([]*domain.Task, error)
- func (m *MockTaskRepository) Move(_ context.Context, taskID string, newStatus domain.TaskStatus, position int) error
- func (m *MockTaskRepository) Search(_ context.Context, query string, projectID string, offset, limit int) ([]*domain.Task, error)
- func (m *MockTaskRepository) UnarchiveTask(_ context.Context, id string) error
- func (m *MockTaskRepository) Update(_ context.Context, task *domain.Task) error
- type MockUserRepository
- func (m *MockUserRepository) AddUser(user *domain.User)
- func (m *MockUserRepository) Count(_ context.Context) (int, error)
- func (m *MockUserRepository) Create(_ context.Context, user *domain.User) error
- func (m *MockUserRepository) Delete(_ context.Context, id string) error
- func (m *MockUserRepository) ExistsByEmail(_ context.Context, email string) (bool, error)
- func (m *MockUserRepository) ExistsByUsername(_ context.Context, username string) (bool, error)
- func (m *MockUserRepository) GetByEmail(_ context.Context, email string) (*domain.User, error)
- func (m *MockUserRepository) GetByID(_ context.Context, id string) (*domain.User, error)
- func (m *MockUserRepository) GetByUsername(_ context.Context, username string) (*domain.User, error)
- func (m *MockUserRepository) List(_ context.Context, offset, limit int) ([]*domain.User, error)
- func (m *MockUserRepository) Update(_ context.Context, user *domain.User) error
- type TestCase
- type TestUserKeyType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MockProject ¶
MockProject creates a mock project for testing.
func NewTestRouter ¶
NewTestRouter creates a new Gin router for testing.
func TestContextWithUser ¶
TestContextWithUser creates a test context with a user.
func TestContextWithValue ¶
TestContextWithValue creates a test context with a value.
Types ¶
type HTTPTestHelper ¶
type HTTPTestHelper struct {
// contains filtered or unexported fields
}
HTTPTestHelper provides utilities for HTTP testing.
func NewHTTPTestHelper ¶
func NewHTTPTestHelper(t *testing.T, router *gin.Engine) *HTTPTestHelper
NewHTTPTestHelper creates a new HTTP test helper.
func (*HTTPTestHelper) AssertHeader ¶
func (h *HTTPTestHelper) AssertHeader(recorder *httptest.ResponseRecorder, header, expectedValue string)
AssertHeader asserts that the response has the expected header value.
func (*HTTPTestHelper) AssertJSON ¶
func (h *HTTPTestHelper) AssertJSON(recorder *httptest.ResponseRecorder, expected interface{})
AssertJSON asserts that the response body matches the expected JSON.
func (*HTTPTestHelper) AssertStatus ¶
func (h *HTTPTestHelper) AssertStatus(recorder *httptest.ResponseRecorder, expectedStatus int)
AssertStatus asserts that the response has the expected status code.
func (*HTTPTestHelper) DELETE ¶
func (h *HTTPTestHelper) DELETE(url string, headers map[string]string) *httptest.ResponseRecorder
DELETE performs a DELETE request.
func (*HTTPTestHelper) GET ¶
func (h *HTTPTestHelper) GET(url string, headers map[string]string) *httptest.ResponseRecorder
GET performs a GET request.
func (*HTTPTestHelper) POST ¶
func (h *HTTPTestHelper) POST(url string, body interface{}, headers map[string]string) *httptest.ResponseRecorder
POST performs a POST request.
func (*HTTPTestHelper) PUT ¶
func (h *HTTPTestHelper) PUT(url string, body interface{}, headers map[string]string) *httptest.ResponseRecorder
PUT performs a PUT request.
func (*HTTPTestHelper) Request ¶
func (h *HTTPTestHelper) Request( method, url string, body interface{}, headers map[string]string, ) *httptest.ResponseRecorder
Request performs an HTTP request and returns the response.
func (*HTTPTestHelper) RunTestCases ¶
func (h *HTTPTestHelper) RunTestCases(testCases []TestCase)
RunTestCases runs a slice of test cases.
type MockProjectRepository ¶
type MockProjectRepository struct {
// contains filtered or unexported fields
}
MockProjectRepository implements ProjectRepository for testing.
func NewMockProjectRepository ¶
func NewMockProjectRepository() *MockProjectRepository
NewMockProjectRepository creates a new mock project repository.
func (*MockProjectRepository) AddProject ¶
func (m *MockProjectRepository) AddProject(project *domain.Project)
AddProject adds a project to mock repository for testing.
func (*MockProjectRepository) Count ¶
func (m *MockProjectRepository) Count(_ context.Context) (int, error)
Count returns the total number of projects.
func (*MockProjectRepository) Delete ¶
func (m *MockProjectRepository) Delete(_ context.Context, id string) error
Delete deletes a project by ID.
func (*MockProjectRepository) ExistsBySlug ¶
ExistsBySlug checks if a project exists with the given slug.
func (*MockProjectRepository) GetMemberProjects ¶
func (m *MockProjectRepository) GetMemberProjects( _ context.Context, userID string, offset, limit int, ) ([]*domain.Project, error)
GetMemberProjects retrieves all projects where user has access.
func (*MockProjectRepository) List ¶
func (m *MockProjectRepository) List(_ context.Context, offset, limit int) ([]*domain.Project, error)
List retrieves projects with pagination.
func (*MockProjectRepository) ListByMember ¶
func (m *MockProjectRepository) ListByMember( _ context.Context, memberID string, offset, limit int, ) ([]*domain.Project, error)
ListByMember retrieves projects where a user is a member.
func (*MockProjectRepository) ListByOwner ¶
func (m *MockProjectRepository) ListByOwner( _ context.Context, ownerID string, offset, limit int, ) ([]*domain.Project, error)
ListByOwner retrieves projects owned by a specific user.
type MockTaskRepository ¶
type MockTaskRepository struct {
Tasks map[string]*domain.Task
SubtasksByParent map[string][]*domain.Task
DependenciesByTask map[string][]*domain.Task
MoveCallLog map[string]bool
SubtasksDuplicated map[string]bool
ForceCreateError bool
ForceGetSubtasksError bool
ForceGetDependenciesError bool
ForceMoveError bool
// contains filtered or unexported fields
}
MockTaskRepository implements TaskRepository for testing enhanced functionality.
func NewMockTaskRepository ¶
func NewMockTaskRepository() *MockTaskRepository
NewMockTaskRepository creates a new mock task repository.
func (*MockTaskRepository) AddTask ¶
func (m *MockTaskRepository) AddTask(task *domain.Task)
AddTask adds a task to mock repository for testing.
func (*MockTaskRepository) ArchiveTask ¶
func (m *MockTaskRepository) ArchiveTask(_ context.Context, id string) error
ArchiveTask archives a task instead of deleting it.
func (*MockTaskRepository) BulkDelete ¶
func (m *MockTaskRepository) BulkDelete(_ context.Context, ids []string) error
BulkDelete deletes multiple tasks.
func (*MockTaskRepository) BulkUpdate ¶
BulkUpdate updates multiple tasks.
func (*MockTaskRepository) BulkUpdateStatus ¶
func (m *MockTaskRepository) BulkUpdateStatus(_ context.Context, taskIDs []string, newStatus domain.TaskStatus) error
BulkUpdateStatus updates multiple tasks with the same status.
func (*MockTaskRepository) Count ¶
func (m *MockTaskRepository) Count(_ context.Context) (int, error)
Count returns the total number of tasks matching criteria.
func (*MockTaskRepository) CountByAssignee ¶
CountByAssignee returns the number of tasks assigned to a user.
func (*MockTaskRepository) CountByProject ¶
CountByProject returns the number of tasks in a project.
func (*MockTaskRepository) CountByStatus ¶
func (m *MockTaskRepository) CountByStatus(_ context.Context, status domain.TaskStatus) (int, error)
CountByStatus returns the number of tasks with a specific status.
func (*MockTaskRepository) Delete ¶
func (m *MockTaskRepository) Delete(_ context.Context, id string) error
Delete deletes a task by ID.
func (*MockTaskRepository) ExistsByID ¶
ExistsByID checks if a task exists by ID.
func (*MockTaskRepository) GetByProject ¶
func (m *MockTaskRepository) GetByProject( _ context.Context, projectID string, filters repository.TaskFilters, ) ([]*domain.Task, error)
GetByProject retrieves tasks for a specific project with advanced filtering.
func (*MockTaskRepository) GetDependencies ¶
func (m *MockTaskRepository) GetDependencies(_ context.Context, taskID string) ([]*domain.Task, error)
GetDependencies retrieves dependency tasks for a task.
func (*MockTaskRepository) GetSubtasks ¶
func (m *MockTaskRepository) GetSubtasks(_ context.Context, parentID string) ([]*domain.Task, error)
GetSubtasks retrieves subtasks for a parent task.
func (*MockTaskRepository) GetTasksByFilter ¶
func (m *MockTaskRepository) GetTasksByFilter( _ context.Context, filters repository.TaskFilters, ) ([]*domain.Task, error)
GetTasksByFilter retrieves tasks using advanced filters.
func (*MockTaskRepository) ListByAssignee ¶
func (m *MockTaskRepository) ListByAssignee( _ context.Context, assigneeID string, offset, limit int, ) ([]*domain.Task, error)
ListByAssignee retrieves tasks assigned to a specific user.
func (*MockTaskRepository) ListByCreator ¶
func (m *MockTaskRepository) ListByCreator( _ context.Context, creatorID string, offset, limit int, ) ([]*domain.Task, error)
ListByCreator retrieves tasks created by a specific user.
func (*MockTaskRepository) ListByProject ¶
func (m *MockTaskRepository) ListByProject( _ context.Context, projectID string, offset, limit int, ) ([]*domain.Task, error)
ListByProject retrieves tasks for a specific project (legacy method).
func (*MockTaskRepository) ListByStatus ¶
func (m *MockTaskRepository) ListByStatus( _ context.Context, status domain.TaskStatus, offset, limit int, ) ([]*domain.Task, error)
ListByStatus retrieves tasks by status.
func (*MockTaskRepository) Move ¶
func (m *MockTaskRepository) Move(_ context.Context, taskID string, newStatus domain.TaskStatus, position int) error
Move moves a task to a new status and position.
func (*MockTaskRepository) Search ¶
func (m *MockTaskRepository) Search( _ context.Context, query string, projectID string, offset, limit int, ) ([]*domain.Task, error)
Search searches tasks by title, description or content.
func (*MockTaskRepository) UnarchiveTask ¶
func (m *MockTaskRepository) UnarchiveTask(_ context.Context, id string) error
UnarchiveTask unarchives a task.
type MockUserRepository ¶
type MockUserRepository struct {
// contains filtered or unexported fields
}
MockUserRepository implements UserRepository for testing.
func NewMockUserRepository ¶
func NewMockUserRepository() *MockUserRepository
NewMockUserRepository creates a new mock user repository.
func (*MockUserRepository) AddUser ¶
func (m *MockUserRepository) AddUser(user *domain.User)
AddUser adds a user to mock repository for testing.
func (*MockUserRepository) Count ¶
func (m *MockUserRepository) Count(_ context.Context) (int, error)
Count returns the total number of users.
func (*MockUserRepository) Delete ¶
func (m *MockUserRepository) Delete(_ context.Context, id string) error
Delete deletes a user by ID.
func (*MockUserRepository) ExistsByEmail ¶
ExistsByEmail checks if a user exists with the given email.
func (*MockUserRepository) ExistsByUsername ¶
ExistsByUsername checks if a user exists with the given username.
func (*MockUserRepository) GetByEmail ¶
GetByEmail retrieves a user by email.
func (*MockUserRepository) GetByUsername ¶
func (m *MockUserRepository) GetByUsername(_ context.Context, username string) (*domain.User, error)
GetByUsername retrieves a user by username.
type TestCase ¶
type TestCase struct {
Body interface{}
ExpectedBody interface{}
Headers map[string]string
SetupFunc func(t *testing.T)
CleanupFunc func(t *testing.T)
Name string
Method string
URL string
ExpectedStatus int
}
TestCase represents a test case for HTTP handlers.
type TestUserKeyType ¶
type TestUserKeyType string
TestUserKeyType is the type used for user context key.
const TestUserKey TestUserKeyType = "user"
TestUserKey is the key used to store user in test context.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package integration contains test-specific migration for integration tests
|
Package integration contains test-specific migration for integration tests |