Contributing
Testing
Running and writing tests
Testing
Bingsan has a comprehensive test suite including unit, integration, and benchmark tests.
Running Tests
# Run all tests
make test
# Run with verbose output
go test -v ./...
# Run specific package
go test -v ./internal/api/handlers/...
# Run specific test
go test -v -run TestTableCreate ./tests/unit/...Test Structure
tests/
├── unit/ # Unit tests
├── integration/ # Integration tests (require database)
├── contract/ # API contract tests
├── e2e/ # End-to-end tests
├── benchmark/ # Performance benchmarks
└── fixtures/ # Test data and SQL fixturesUnit Tests
Unit tests are located alongside the code or in tests/unit/:
# Run unit tests only
go test -v ./internal/...Integration Tests
Integration tests require a running PostgreSQL instance:
# Start dependencies
make docker-up
# Run integration tests
make test-integrationIntegration tests use the integration build tag:
//go:build integration
package integration
func TestDatabaseOperations(t *testing.T) {
// ...
}Contract Tests
Contract tests verify API compliance with the Iceberg REST spec:
go test -v ./tests/contract/...Writing Tests
Test Naming
func TestFeature_Scenario_ExpectedBehavior(t *testing.T) {
// Example: TestTableCreate_WithValidInput_ReturnsCreatedTable
}Table-Driven Tests
func TestValidation(t *testing.T) {
tests := []struct {
name string
input string
wantErr bool
}{
{"valid input", "test", false},
{"empty input", "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := Validate(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}Test Fixtures
Use SQL fixtures for database tests:
tests/fixtures/
├── namespaces.sql
├── tables.sql
└── cleanup.sqlBenchmarks
# Run all benchmarks
make bench
# Run specific benchmark
go test -bench=BenchmarkTable -benchmem ./tests/benchmark/...
# Compare before/after
go test -bench=. ./tests/benchmark/... | tee before.txt
# Make changes
go test -bench=. ./tests/benchmark/... | tee after.txt
benchstat before.txt after.txtCoverage
# Generate coverage report
go test -coverprofile=coverage.out ./...
# View in browser
go tool cover -html=coverage.out
# Check coverage percentage
go tool cover -func=coverage.outCI Integration
Tests run automatically on pull requests via GitHub Actions. The CI pipeline:
- Runs linters (golangci-lint)
- Runs unit tests
- Runs integration tests with PostgreSQL service
- Reports coverage