testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testutil 提供测试共享工具

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoRequest

func DoRequest(router *gin.Engine, method, path string, body ...http.Handler) *httptest.ResponseRecorder

DoRequest 执行 HTTP 请求并返回响应记录器

func DoRequestWithBody

func DoRequestWithBody(t *testing.T, router *gin.Engine, method, path string, body []byte) *httptest.ResponseRecorder

DoRequestWithBody 执行带 body 的 HTTP 请求

func RequireStatus

func RequireStatus(t *testing.T, w *httptest.ResponseRecorder, expected int)

RequireStatus 断言 HTTP 响应状态码

func SetupTestDB

func SetupTestDB(t *testing.T, models ...interface{}) *gorm.DB

SetupTestDB 创建内存 SQLite 测试数据库并自动迁移给定模型

func SetupTestRouter

func SetupTestRouter(t *testing.T) *gin.Engine

SetupTestRouter 创建测试模式的 gin 路由器

func TestLogger

func TestLogger() *zap.Logger

TestLogger 返回静默的 zap.Logger

Types

This section is empty.

Jump to

Keyboard shortcuts

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