testx

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package testx 提供集成测试的基础设施:以 docker 容器启动依赖服务并返回连接信息。 固定名容器跨测试进程复用以加速重复运行;各存储的客户端库封装隔离于子包 (如 testx/postgres),仅需连接信息的调用方不受客户端依赖传染。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgres added in v1.8.0

func NewPostgres(t *testing.T) string

NewPostgres 为单个测试准备一套干净的 Postgres 数据库,返回其 DSN。 固定名容器跨测试进程复用(测试结束有意保留容器以加速下次运行), 每个测试用例在容器内创建随机名数据库实现隔离,t.Cleanup 负责删库。 客户端库由调用方按所用技术栈自选;gorm 版便利封装见子包 testx/postgres。

func NewRedis

func NewRedis(t *testing.T) string

NewRedis 为测试准备 Redis 容器,返回宿主机访问地址 host:port。 Redis 不引入客户端依赖,调用方按所用客户端库自行连接; 容器跨测试复用,测试间以 key 前缀隔离数据。

func StopPostgres

func StopPostgres() error

StopPostgres 停止并删除 Postgres 测试容器。 测试流程无需调用(容器有意保留以加速下次运行,CI runner 为一次性虚机亦无需清理), 仅供本地开发欲彻底清理时在代码中调用,亦可直接执行: docker stop godddtest && docker rm godddtest

func StopRedis

func StopRedis() error

StopRedis 停止并删除 Redis 测试容器。 测试流程无需调用(容器有意保留以加速下次运行,CI runner 为一次性虚机亦无需清理), 仅供本地开发欲彻底清理时手动使用。

Types

This section is empty.

Directories

Path Synopsis
Package docker 提供测试期间启动与停止 docker 容器的能力。
Package docker 提供测试期间启动与停止 docker 容器的能力。
Package postgres 提供基于 gorm 的 Postgres 测试便利封装。
Package postgres 提供基于 gorm 的 Postgres 测试便利封装。

Jump to

Keyboard shortcuts

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