apitesting

package
v0.0.0-...-72e56ea Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestAPI

func NewTestAPI(t *testing.T, chDB *ClickHouseDB) *handlers.API

NewTestAPI creates an isolated *handlers.API for a single test with a per-test ClickHouse database (with full schema migrations). This is the most common test setup pattern.

func NewTestAPIAll

func NewTestAPIAll(t *testing.T, chDB *ClickHouseDB, pgDB *DB, neo4jDB *Neo4jDB, seedFunc func(ctx context.Context, session neo4j.Session) error) *handlers.API

NewTestAPIAll creates an isolated *handlers.API with ClickHouse, PostgreSQL, and Neo4j connections. Pass nil for any component to skip it.

func NewTestAPIBare

func NewTestAPIBare(t *testing.T, chDB *ClickHouseDB) *handlers.API

NewTestAPIBare creates an isolated *handlers.API for a single test with a per-test ClickHouse database (empty, no migrations). Use this for tests that create their own table schemas.

func NewTestAPIPg

func NewTestAPIPg(t *testing.T, pgDB *DB) *handlers.API

NewTestAPIPg creates an isolated *handlers.API for a single test with a PostgreSQL pool (with migrations applied).

func NewTestPool

func NewTestPool(t *testing.T, db *DB) *pgxpool.Pool

NewTestPool creates a new pgxpool connected to the test container.

func SetupClickHouseForTest

func SetupClickHouseForTest(t *testing.T, db *ClickHouseDB) (driver.Conn, string)

SetupClickHouseForTest creates a per-test ClickHouse database and returns the direct connection and database name. No proxy registration.

func SetupClickHouseWithMigrationsForTest

func SetupClickHouseWithMigrationsForTest(t *testing.T, db *ClickHouseDB) (driver.Conn, string)

SetupClickHouseWithMigrationsForTest creates a per-test ClickHouse database with full schema migrations and returns the direct connection and database name.

func SetupNeo4jForTest

func SetupNeo4jForTest(t *testing.T, db *Neo4jDB) neo4j.Client

SetupNeo4jForTest creates a read-only Neo4j client for the test. Does NOT touch config.Neo4jClient.

func SetupNeo4jWithDataForTest

func SetupNeo4jWithDataForTest(t *testing.T, db *Neo4jDB, seedFunc func(ctx context.Context, session neo4j.Session) error) neo4j.Client

SetupNeo4jWithDataForTest seeds data and returns a read-only Neo4j client. Does NOT touch config.Neo4jClient.

func SetupPostgresForTest

func SetupPostgresForTest(t *testing.T, db *DB) *pgxpool.Pool

Does NOT touch config.PgPool.

func WaitForPostgres

func WaitForPostgres() *wait.LogStrategy

WaitForPostgres is a convenience wait strategy for PostgreSQL.

Types

type ClickHouseDB

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

ClickHouseDB represents a ClickHouse test container.

func NewClickHouseDB

func NewClickHouseDB(ctx context.Context, log *slog.Logger, cfg *ClickHouseDBConfig) (*ClickHouseDB, error)

NewClickHouseDB creates a new ClickHouse testcontainer.

func (*ClickHouseDB) Addr

func (db *ClickHouseDB) Addr() string

Addr returns the ClickHouse native protocol address (host:port).

func (*ClickHouseDB) Close

func (db *ClickHouseDB) Close()

Close terminates the ClickHouse container.

func (*ClickHouseDB) Database

func (db *ClickHouseDB) Database() string

Database returns the ClickHouse database name.

func (*ClickHouseDB) HTTPAddr

func (db *ClickHouseDB) HTTPAddr() string

HTTPAddr returns the HTTP endpoint URL (http://host:port) for the ClickHouse container.

func (*ClickHouseDB) Password

func (db *ClickHouseDB) Password() string

Password returns the ClickHouse password.

func (*ClickHouseDB) Username

func (db *ClickHouseDB) Username() string

Username returns the ClickHouse username.

type ClickHouseDBConfig

type ClickHouseDBConfig struct {
	Database       string
	Username       string
	Password       string
	Port           string
	ContainerImage string
}

ClickHouseDBConfig holds the ClickHouse test container configuration.

func (*ClickHouseDBConfig) Validate

func (cfg *ClickHouseDBConfig) Validate() error

type DB

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

DB represents a PostgreSQL test container.

func NewDB

func NewDB(ctx context.Context, log *slog.Logger, cfg *DBConfig) (*DB, error)

NewDB creates a new PostgreSQL testcontainer.

func (*DB) Close

func (db *DB) Close()

Close terminates the PostgreSQL container.

func (*DB) ConnStr

func (db *DB) ConnStr() string

ConnStr returns the PostgreSQL connection string.

type DBConfig

type DBConfig struct {
	Database       string
	Username       string
	Password       string
	ContainerImage string
}

DBConfig holds the PostgreSQL test container configuration.

func (*DBConfig) Validate

func (cfg *DBConfig) Validate() error

type Neo4jDB

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

Neo4jDB represents a Neo4j test container.

func NewNeo4jDB

func NewNeo4jDB(ctx context.Context, log *slog.Logger, cfg *Neo4jDBConfig) (*Neo4jDB, error)

NewNeo4jDB creates a new Neo4j testcontainer.

func (*Neo4jDB) BoltURL

func (db *Neo4jDB) BoltURL() string

BoltURL returns the Bolt protocol URL for the Neo4j container.

func (*Neo4jDB) Close

func (db *Neo4jDB) Close()

Close terminates the Neo4j container.

func (*Neo4jDB) Password

func (db *Neo4jDB) Password() string

Password returns the Neo4j password.

func (*Neo4jDB) Username

func (db *Neo4jDB) Username() string

Username returns the Neo4j username.

type Neo4jDBConfig

type Neo4jDBConfig struct {
	Username       string
	Password       string
	ContainerImage string
}

Neo4jDBConfig holds the Neo4j test container configuration.

func (*Neo4jDBConfig) Validate

func (cfg *Neo4jDBConfig) Validate() error

Jump to

Keyboard shortcuts

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