servertest

package
v0.50.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: MIT Imports: 23 Imported by: 1

Documentation

Overview

Package servertest 针对 server 的测试用例

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildHandler

func BuildHandler(code int) server.HandlerFunc

BuildHandler 生成以 code 作为状态码和内容输出的路由处理函数

func NewServer

func NewServer(a *assert.Assertion, o *server.Options) *server.Server

NewServer 返回功能齐全的 Server 实例

Types

type Tester

type Tester struct {
	// contains filtered or unexported fields
}

func NewTester

func NewTester(a *assert.Assertion, o *server.Options) *Tester

NewTester 声明一个 server 实例

func (*Tester) Close

func (s *Tester) Close(shutdown time.Duration)

func (*Tester) Delete

func (s *Tester) Delete(path string) *rest.Request

func (*Tester) Get

func (s *Tester) Get(path string) *rest.Request

func (*Tester) GoServe

func (s *Tester) GoServe()

func (*Tester) NewRequest

func (s *Tester) NewRequest(method, path string, client *http.Client) *rest.Request

NewRequest 发起新的请求

path 为请求路径,如果没有 http:// 和 https:// 前缀,则会自动加上 http://localhost 作为其域名地址; client 如果为空,则采用 http.DefaultClient 作为默认值;

func (*Tester) NewRouter

func (s *Tester) NewRouter(ms ...server.Middleware) *server.Router

NewRouter 创建一个默认的路由

相当于:

s.Server().NewRouter("default", "http://localhost:8080/", nil)

NOTE: 如果需要多个路由,请使用 Server().NewRouter 并指定正确的 group.Matcher 对象, 或是将 Tester.NewRouter 放在最后。

func (*Tester) Server

func (s *Tester) Server() *server.Server

func (*Tester) Wait

func (s *Tester) Wait()

Wait 等待 GoServe 退出

Jump to

Keyboard shortcuts

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