Skip to content

v0.1.0

Choose a tag to compare

@yuku yuku released this 23 Jul 22:00
· 9 commits to main since this release
6b51140

Initial release of testdbpool, a Go library for efficient PostgreSQL test database pooling.

Features

  • Template-based Database Creation: Fast database setup using PostgreSQL's CREATE DATABASE ... TEMPLATE feature
  • Connection Pool Reuse: Eliminates connection establishment overhead by reusing existing connection pools
  • Concurrent Test Support: Safe parallel test execution with fair resource allocation via numpool
  • Automatic Database Reset: Customizable reset functions to clean databases between test uses
  • Resource Efficiency: Optimal resource utilization ideal for CI environments and resource-constrained servers
  • Cross-package Sharing: Multiple test packages can share pools using common identifiers

Installation

go get github.com/yuku/testdbpool@v0.1.0

Quick Start

func TestMain(m *testing.M) {
    // Setup test database pool in TestMain
    pool, err := testdbpool.New(ctx, &testdbpool.Config{
        ID:           "myapp-test",
        Pool:         connPool,
        SetupTemplate: setupSchema,
        ResetDatabase: resetData,
    })
    if err \!= nil {
        panic(err)
    }
    
    code := m.Run()
    pool.Cleanup()
    os.Exit(code)
}

func TestExample(t *testing.T) {
    db, err := pool.Acquire(ctx)
    if err \!= nil {
        t.Fatal(err)
    }
    defer db.Release(ctx)
    
    // Use db.Pool() for database operations
}

Documentation

  • 📖 README - Complete usage guide with examples
  • 📚 GoDoc - API reference
  • 🔄 Workflow Diagram - Visual guide to how testdbpool works

Requirements

  • PostgreSQL 14+ (for reliable template database support)
  • Go 1.22+

Performance Benefits

  • Fast database creation through template cloning vs schema migration
  • Efficient cleanup using TRUNCATE vs database recreation
  • Connection pool reuse eliminates connection establishment overhead
  • Optimal resource utilization in CI and resource-constrained environments