testutil

package
v0.0.0-...-9f83ea1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testutil 测试辅助工具

使用:

func TestXxx(t *testing.T) {
    testutil.SetupTestDB(t)
    // g.DB() 已指向 codcms_test
    // 使用 service.Article().Add/Get/Edit/Del ...
}

环境准备:

CREATE DATABASE codcms_test CHARACTER SET utf8mb4;
mysql codcms_test < sql/codcms.sql

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupTables

func CleanupTables(t *testing.T, tables ...string)

CleanupTables deletes all rows from the specified tables (for test isolation). Call at the start of each test function that modifies data to prevent state coupling. 清理指定表的所有数据,用于测试隔离。每个会修改数据的测试函数开头调用。

func SetupTestDB

func SetupTestDB(t *testing.T)

SetupTestDB 注入测试数据库配置到 g.DB()。 每个 TestXxx 函数调用一次,sync.Once 保证只初始化一次。

func TestDBConfig

func TestDBConfig() gdb.ConfigNode

TestDBConfig 返回测试数据库配置(供 gdb.New 使用)

Types

This section is empty.

Jump to

Keyboard shortcuts

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