Help us shape the future of Go! Take the 2026 Go Developer Survey

testdb

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testdb 给集成测试提供一个用完即删的独立 schema。

连接串只从 LUMO_TEST_DSN 取,没设时跳过测试,所以不带数据库也能跑 go test。 库名必须含 test:同一实例上还有开发库和别的项目的库,连错一次就是一次事故, 这道闸门不能靠人记。每次调用建一个随机命名的 schema,测试结束连同里面的表一起删掉, 多个测试包并行跑也互不干扰。

Index

Constants

View Source
const EnvDSN = "LUMO_TEST_DSN"

EnvDSN 是测试库连接串所在的环境变量。

Variables

This section is empty.

Functions

func DSN

func DSN(t testing.TB) string

DSN 建一个新 schema,返回把 search_path 指向它的连接串;测试结束时删除该 schema。

func Open

func Open(t testing.TB) *database.DB

Open 在新 schema 上开一个连接池,测试结束时关闭。

func OpenCore

func OpenCore(t testing.TB) *database.DB

OpenCore 在新 schema 上开连接池并跑完核心迁移,给只用到核心表的测试用。

Types

This section is empty.

Jump to

Keyboard shortcuts

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