routertest

package
v7.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package routertest 提供针对路由的测试用例

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tester

type Tester[T any] struct {
	// contains filtered or unexported fields
}

func NewTester

func NewTester[T any](c mux.CallOf[T], notFound T, m, o types.BuildNodeHandleOf[T]) *Tester[T]

func (*Tester[T]) Bench

func (t *Tester[T]) Bench(b *testing.B, h T)

Bench 执行所有的性能测试

h 表示路由的处理函数,只要向终端输出 URL.Path 值即可, 以 T 的类型为 http.HandlerFunc 为例:

func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte(r.URL.Path))
}

func (*Tester[T]) Params

func (t *Tester[T]) Params(a *assert.Assertion, f func(ctx *types.Context) T)

Params 测试参数是否正常

f 返回一个路由处理函数,该函数必须要将获得的参数写入 ctx。

func (*Tester[T]) Serve

func (t *Tester[T]) Serve(a *assert.Assertion, h func(status int) T)

Serve 测试路由是否正常

h 返回路由处理函数,该函数只要输出 status 作为其状态码即可。

Jump to

Keyboard shortcuts

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