Documentation ¶
Index ¶
- Variables
- func BuildHTTP1Request(method string, header map[string]string, body []byte) (types.HeaderMap, types.IoBuffer)
- type Client
- type ClientConfig
- type ClientStats
- type ConnClient
- type ConnStats
- type HTTPResonseConfig
- type HTTPServe
- type MakeRequestFunc
- type MockServer
- type Response
- type ResponseBuilder
- type ResponseVerify
- type ResponseWriterWrapper
- type ServeFunc
- type ServerStats
- type StatsConn
- type StatsListener
- type VerifyConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultBuilder = &ResponseBuilder{ StatusCode: http.StatusOK, Header: map[string]string{ "mosn-test-default": "http1", }, Body: []byte("default-http1"), }
View Source
var DefaultErrorBuilder = &ResponseBuilder{ StatusCode: http.StatusInternalServerError, Header: map[string]string{ "error-mesage": "no matched config", }, }
View Source
var DefaultHTTPServe = &HTTPServe{ Configs: map[string]*HTTPResonseConfig{ "/": &HTTPResonseConfig{ Builder: DefaultBuilder, ErrorBuidler: DefaultErrorBuilder, }, }, }
View Source
var DefaultVeirfy = &VerifyConfig{ ExpectedStatus: http.StatusOK, }
Functions ¶
Types ¶
type Client ¶
type Client struct { Cfg *ClientConfig // Stats Stats *ClientStats // contains filtered or unexported fields }
func NewClient ¶
func NewClient(cfg *ClientConfig, maxConnections uint32) *Client
type ClientConfig ¶
type ClientConfig struct { Addr string MakeRequest MakeRequestFunc RequestMethod string RequestHeader map[string]string RequestBody []byte // request timeout is used for sync call // if zero, we set default request time, 5 second RequestTImeout time.Duration // if Verify is nil, just expected returns success Verify ResponseVerify }
func CreateSimpleConfig ¶
func CreateSimpleConfig(addr string) *ClientConfig
type ClientStats ¶
type ClientStats struct { *ServerStats // contains filtered or unexported fields }
func NewClientStats ¶
func NewClientStats() *ClientStats
func (*ClientStats) ExpectedResponse ¶
func (c *ClientStats) ExpectedResponse() (uint32, uint32)
func (*ClientStats) Response ¶
func (c *ClientStats) Response(expected bool)
type ConnClient ¶
type ConnClient struct { MakeRequest MakeRequestFunc SyncTimeout time.Duration // contains filtered or unexported fields }
func NewConnClient ¶
func NewConnClient(addr string, f MakeRequestFunc) (*ConnClient, error)
func (*ConnClient) Close ¶
func (c *ConnClient) Close()
func (*ConnClient) IsClosed ¶
func (c *ConnClient) IsClosed() bool
func (*ConnClient) OnEvent ¶
func (c *ConnClient) OnEvent(event types.ConnectionEvent)
type ConnStats ¶
type ConnStats struct {
// contains filtered or unexported fields
}
func (*ConnStats) ActiveConnection ¶
func (s *ConnStats) ActiveConnection()
func (*ConnStats) CloseConnection ¶
func (s *ConnStats) CloseConnection()
type HTTPResonseConfig ¶
type HTTPResonseConfig struct { ExpectedHeader http.Header // map[string][]string UnexpectedHeaderKey []string ExpectedMethod string // Builder *ResponseBuilder ErrorBuidler *ResponseBuilder }
TODO: support more
func (*HTTPResonseConfig) ServeHTTP ¶
func (cfg *HTTPResonseConfig) ServeHTTP(w http.ResponseWriter, r *http.Request)
type HTTPServe ¶
type HTTPServe struct {
Configs map[string]*HTTPResonseConfig
}
func (*HTTPServe) Serve ¶
func (s *HTTPServe) Serve(srv *MockServer)
type MakeRequestFunc ¶
type MockServer ¶
type MockServer struct { *http.Server *ServerStats Addr string Mux map[string]func(http.ResponseWriter, *http.Request) // contains filtered or unexported fields }
func NewMockServer ¶
func NewMockServer(addr string, f ServeFunc) *MockServer
func (*MockServer) HandleFunc ¶
func (srv *MockServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
func (*MockServer) ServeHTTP ¶
func (srv *MockServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
A wrapper of ServerHTTP
func (*MockServer) Start ¶
func (srv *MockServer) Start()
type Response ¶
type Response struct { Header mosnhttp.ResponseHeader Data []byte Cost time.Duration }
Client
type ResponseBuilder ¶
func (*ResponseBuilder) Build ¶
func (b *ResponseBuilder) Build(w http.ResponseWriter) (int, error)
type ResponseVerify ¶
type ResponseWriterWrapper ¶
type ResponseWriterWrapper struct { http.ResponseWriter // contains filtered or unexported fields }
func (*ResponseWriterWrapper) WriteHeader ¶
func (w *ResponseWriterWrapper) WriteHeader(code int)
type ServeFunc ¶
type ServeFunc func(srv *MockServer)
type ServerStats ¶
type ServerStats struct { *ConnStats // contains filtered or unexported fields }
func NewServerStats ¶
func NewServerStats(cs *ConnStats) *ServerStats
func (*ServerStats) Request ¶
func (s *ServerStats) Request()
func (*ServerStats) RequestStats ¶
func (s *ServerStats) RequestStats() uint32
func (*ServerStats) Response ¶
func (s *ServerStats) Response(status int16)
func (*ServerStats) ResponseStats ¶
func (s *ServerStats) ResponseStats() map[int16]uint32
type StatsListener ¶
type StatsListener struct { // stats *ConnStats // contains filtered or unexported fields }
StatsListener implements a net.Listener for http.Server
func NewStatsListener ¶
func NewStatsListener(ln net.Listener) *StatsListener
func (*StatsListener) Addr ¶
func (sl *StatsListener) Addr() net.Addr
func (*StatsListener) Close ¶
func (sl *StatsListener) Close() error
type VerifyConfig ¶
type VerifyConfig struct { ExpectedStatus int // if ExepctedHeader is nil, means do not care about header // if ExepctedHeader is exists, means resposne Header should contain all the ExpectedHeader // TODO : support regex ExpectedHeader map[string]string // if ExpectedBody is nil, means do not care about body // TODO: support regex ExpectedBody []byte // if ExpectedRT is zero, means do not care about rt // if ExpectedRT is not zero, means response's rt should no more than it ExpectedRT time.Duration // if MinRT is zero means do not care about it // if MinRT is not zero, means response's rt should more than it MinRT time.Duration }
func (*VerifyConfig) Verify ¶
func (cfg *VerifyConfig) Verify(resp *Response) bool
Click to show internal directories.
Click to hide internal directories.