testserver

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package testserver 提供标准 gRPC 与额外 HTTP 接口的测试环境。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPServer added in v1.3.3

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

HTTPServer 持有测试期间运行的标准 Server 和指向该服务的 HTTP Client。

func NewHTTP added in v1.3.3

func NewHTTP(t testing.TB, method string, path string, handler standard.HandlerFunc, opts ...standard.Option) *HTTPServer

NewHTTP 在本地回环地址启动额外 HTTP 接口,并在测试结束时自动释放资源。

func (*HTTPServer) Client added in v1.3.3

func (s *HTTPServer) Client() *http.Client

Client 返回连接到测试 Server 的 HTTP Client。

func (*HTTPServer) Close added in v1.3.3

func (s *HTTPServer) Close()

Close 释放 HTTP Client、Server 和 Listener,支持重复调用。

func (*HTTPServer) URL added in v1.3.3

func (s *HTTPServer) URL(path string) string

URL 返回测试 Server 上指定路径的完整 URL。

type Server

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

Server 持有测试期间运行的标准 Server 和指向该服务的 ClientConn。

func New

func New(t testing.TB, opts ...standard.Option) *Server

New 启动内存 gRPC Server,并在测试结束时自动释放资源。

func (*Server) Close

func (s *Server) Close()

Close 释放 ClientConn、Server 和 bufconn Listener,支持重复调用。

func (*Server) Conn

func (s *Server) Conn() *grpc.ClientConn

Conn 返回连接到测试 Server 的 gRPC ClientConn。

Jump to

Keyboard shortcuts

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