testing

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package testing provides test utilities, fixtures, and database setup for HR System services. It includes testcontainers integration for isolated testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestConfig

func TestConfig() *config.Config

TestConfig returns a test configuration.

func TestContext

func TestContext() context.Context

TestContext provides a context with test values.

Types

type AssertionHelpers

type AssertionHelpers struct {
	// contains filtered or unexported fields
}

AssertionHelpers provides common test assertions.

func NewAssertionHelpers

func NewAssertionHelpers(t *testing.T) *AssertionHelpers

NewAssertionHelpers creates a new assertion helpers instance.

func (*AssertionHelpers) AssertRecordCount

func (ah *AssertionHelpers) AssertRecordCount(db *gorm.DB, table string, expectedCount int64)

AssertRecordCount checks the number of records in a table.

func (*AssertionHelpers) AssertRecordExists

func (ah *AssertionHelpers) AssertRecordExists(db *gorm.DB, table, column, value string)

AssertRecordExists checks if a record exists in the database.

func (*AssertionHelpers) AssertRecordNotExists

func (ah *AssertionHelpers) AssertRecordNotExists(db *gorm.DB, table, column, value string)

AssertRecordNotExists checks if a record does not exist in the database.

type MockData

type MockData struct{}

MockData provides methods for generating mock test data.

func NewMockData

func NewMockData() *MockData

NewMockData creates a new mock data generator.

func (*MockData) GenerateEmail

func (md *MockData) GenerateEmail(prefix string) string

GenerateEmail generates a test email address.

func (*MockData) GenerateEmployeeNumber

func (md *MockData) GenerateEmployeeNumber() string

GenerateEmployeeNumber generates a test employee number.

func (*MockData) GenerateID

func (md *MockData) GenerateID(prefix string) string

GenerateID generates a test ID.

type SeedData

type SeedData struct {
	// contains filtered or unexported fields
}

SeedData provides methods for seeding test data.

func NewSeedData

func NewSeedData(db *gorm.DB) *SeedData

NewSeedData creates a new seed data helper.

func (*SeedData) CreateEmployee

func (sd *SeedData) CreateEmployee(id, tenantID, employeeNumber, email, fullName string) error

CreateEmployee creates a test employee.

func (*SeedData) CreateTenant

func (sd *SeedData) CreateTenant(id, name string) error

CreateTenant creates a test tenant.

func (*SeedData) CreateUser

func (sd *SeedData) CreateUser(id, tenantID, email, fullName string, roles []string) error

CreateUser creates a test user.

type TestDatabase

type TestDatabase struct {
	DB        *gorm.DB
	Container *postgres.PostgresContainer
	Config    config.DatabaseConfig
}

TestDatabase represents a test database instance.

func SetupTestDB

func SetupTestDB(t *testing.T) *TestDatabase

SetupTestDB creates a test database using testcontainers.

func SetupTestDBWithModels

func SetupTestDBWithModels(t *testing.T, models ...interface{}) *TestDatabase

SetupTestDBWithModels creates a test database and runs migrations for the given models.

func (*TestDatabase) TruncateAllTables

func (td *TestDatabase) TruncateAllTables() error

TruncateAllTables truncates all tables in the test database.

func (*TestDatabase) TruncateTable

func (td *TestDatabase) TruncateTable(tableName string) error

TruncateTable truncates a table for test cleanup.

type TestFixtures

type TestFixtures struct {
	TenantID   string
	UserID     string
	EmployeeID string
	SeedData   *SeedData
}

TestFixtures provides common test fixtures.

func NewTestFixtures

func NewTestFixtures(db *gorm.DB) *TestFixtures

NewTestFixtures creates a new test fixtures helper.

func (*TestFixtures) SetupBasicFixtures

func (tf *TestFixtures) SetupBasicFixtures() error

SetupBasicFixtures creates basic test data (tenant, user, employee).

Jump to

Keyboard shortcuts

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