testutil

package
v0.0.0-...-ee5b157 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testutil provides testing utilities and mock implementations.

Package testutil provides testing utilities and helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockProject

func MockProject(id, title, slug, ownerID string) *domain.Project

MockProject creates a mock project for testing.

func MockTask

func MockTask(id, title, projectID, reporterID string) *domain.Task

MockTask creates a mock task for testing.

func MockUser

func MockUser(id, email, username, name string) *domain.User

MockUser creates a mock user for testing.

func NewTestRouter

func NewTestRouter() *gin.Engine

NewTestRouter creates a new Gin router for testing.

func TestConfig

func TestConfig() config.Config

TestConfig returns a test configuration.

func TestContextWithUser

func TestContextWithUser(user *domain.User) context.Context

TestContextWithUser creates a test context with a user.

func TestContextWithValue

func TestContextWithValue(key, value interface{}) context.Context

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

Count returns the total number of projects.

func (*MockProjectRepository) Create

func (m *MockProjectRepository) Create(_ context.Context, project *domain.Project) error

Create creates a new project.

func (*MockProjectRepository) Delete

Delete deletes a project by ID.

func (*MockProjectRepository) ExistsBySlug

func (m *MockProjectRepository) ExistsBySlug(_ context.Context, slug string) (bool, error)

ExistsBySlug checks if a project exists with the given slug.

func (*MockProjectRepository) GetByID

GetByID retrieves a project by ID.

func (*MockProjectRepository) GetBySlug

func (m *MockProjectRepository) GetBySlug(_ context.Context, slug string) (*domain.Project, error)

GetBySlug retrieves a project by 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.

func (*MockProjectRepository) Update

func (m *MockProjectRepository) Update(_ context.Context, project *domain.Project) error

Update updates an existing project.

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

func (m *MockTaskRepository) BulkUpdate(_ context.Context, tasks []*domain.Task) error

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

func (m *MockTaskRepository) CountByAssignee(_ context.Context, assigneeID string) (int, error)

CountByAssignee returns the number of tasks assigned to a user.

func (*MockTaskRepository) CountByProject

func (m *MockTaskRepository) CountByProject(_ context.Context, projectID string) (int, error)

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) Create

func (m *MockTaskRepository) Create(_ context.Context, task *domain.Task) error

Create creates a new task.

func (*MockTaskRepository) Delete

func (m *MockTaskRepository) Delete(_ context.Context, id string) error

Delete deletes a task by ID.

func (*MockTaskRepository) ExistsByID

func (m *MockTaskRepository) ExistsByID(_ context.Context, id string) (bool, error)

ExistsByID checks if a task exists by ID.

func (*MockTaskRepository) GetByID

func (m *MockTaskRepository) GetByID(_ context.Context, id string) (*domain.Task, error)

GetByID retrieves a task 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.

func (*MockTaskRepository) Update

func (m *MockTaskRepository) Update(_ context.Context, task *domain.Task) error

Update updates an existing 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) Create

func (m *MockUserRepository) Create(_ context.Context, user *domain.User) error

Create creates a new user.

func (*MockUserRepository) Delete

func (m *MockUserRepository) Delete(_ context.Context, id string) error

Delete deletes a user by ID.

func (*MockUserRepository) ExistsByEmail

func (m *MockUserRepository) ExistsByEmail(_ context.Context, email string) (bool, error)

ExistsByEmail checks if a user exists with the given email.

func (*MockUserRepository) ExistsByUsername

func (m *MockUserRepository) ExistsByUsername(_ context.Context, username string) (bool, error)

ExistsByUsername checks if a user exists with the given username.

func (*MockUserRepository) GetByEmail

func (m *MockUserRepository) GetByEmail(_ context.Context, email string) (*domain.User, error)

GetByEmail retrieves a user by email.

func (*MockUserRepository) GetByID

func (m *MockUserRepository) GetByID(_ context.Context, id string) (*domain.User, error)

GetByID retrieves a user by ID.

func (*MockUserRepository) GetByUsername

func (m *MockUserRepository) GetByUsername(_ context.Context, username string) (*domain.User, error)

GetByUsername retrieves a user by username.

func (*MockUserRepository) List

func (m *MockUserRepository) List(_ context.Context, offset, limit int) ([]*domain.User, error)

List retrieves users with pagination.

func (*MockUserRepository) Update

func (m *MockUserRepository) Update(_ context.Context, user *domain.User) error

Update updates an existing user.

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

Jump to

Keyboard shortcuts

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