Contributing Testing Guide - osama1998H/Moca GitHub Wiki

Testing Guide

Unit tests, integration tests, benchmarks, and test utilities.

Unit Tests

Co-located with source files. Run with:

make test                                          # All tests with race detector
go test -race -run TestFunctionName ./pkg/meta/... # Single test

Integration Tests

Use //go:build integration build tag. Require Docker services (PostgreSQL, Redis, Meilisearch):

docker-compose up -d      # Start services
make test-integration     # Run all integration tests

Docker Service Ports

Service Port Credentials
PostgreSQL 16 5433 user: moca, password: moca_test, db: moca_test
Redis 7 6380 (no auth)
Meilisearch v1.12 7700 (no auth)

Benchmarks

Tier 1 packages: pkg/meta, pkg/document, pkg/orm, pkg/api, pkg/hooks.

make bench              # Run benchmarks
make bench-compare      # Compare against baseline (uses benchstat)
make bench-save-baseline # Save current run
make bench-profile      # CPU/memory profiles

Results tracked in bench-latest.txt and bench-baseline.txt.

Test Coverage

142+ test files across the codebase with comprehensive coverage.

Test Utilities

  • internal/testutil/ -- Common test helpers
  • internal/testutil/bench/ -- Benchmark helpers

Related