Documentation ¶
Index ¶
- Variables
- func NewHTTPServer(config interface{}) types.MockServer
- func NewHttpClient(config interface{}) types.MockClient
- type Condition
- type HttpClientConfig
- type HttpConn
- type HttpServerConfig
- type MockHttpClient
- type MockHttpServer
- type RequestConfig
- type ResonseConfig
- type Response
- type ResponseBuilder
- type ResponseWriterWrapper
- type StatsConn
- type StatsListener
- type VerifyConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrClosedConnection = errors.New("send request on closed connection") ErrRequestTimeout = errors.New("sync call timeout") )
Functions ¶
func NewHTTPServer ¶ added in v0.16.0
func NewHTTPServer(config interface{}) types.MockServer
func NewHttpClient ¶ added in v0.16.0
func NewHttpClient(config interface{}) types.MockClient
Types ¶
type Condition ¶ added in v0.16.0
type Condition struct { // If a request contains the expected header, matched this condition. // A request must have the configured header key and value, and can have others headers // which will be ingored. ExpectedHeader map[string][]string `json:"expected_header"` // If a request contains the unexpected header, matched failed. UnexpectedHeaderKey []string `json"unexpected_headerkey"` // If a request's method is in the expected method, matched this condition. ExpectedMethod []string `json:"expected_method"` }
type HttpClientConfig ¶ added in v0.16.0
type HttpClientConfig struct { TargetAddr string `json:"target_address"` MaxConn uint32 `json:"max_connection"` Request *RequestConfig `json:"request_config"` Verify *VerifyConfig `json:"verify_config"` }
func NewHttpClientConfig ¶ added in v0.16.0
func NewHttpClientConfig(config interface{}) (*HttpClientConfig, error)
type HttpConn ¶ added in v0.16.0
type HttpConn struct {
// contains filtered or unexported fields
}
func (*HttpConn) AsyncSendRequest ¶ added in v0.16.0
func (c *HttpConn) AsyncSendRequest(receiver mtypes.StreamReceiveListener, req *RequestConfig)
func (*HttpConn) OnEvent ¶ added in v0.16.0
func (c *HttpConn) OnEvent(event api.ConnectionEvent)
func (*HttpConn) SyncSendRequest ¶ added in v0.16.0
func (c *HttpConn) SyncSendRequest(req *RequestConfig) (*Response, error)
type HttpServerConfig ¶ added in v0.16.0
type HttpServerConfig struct { Addr string `json:"address"` Configs map[string]*ResonseConfig `json:"response_configs"` }
func NewHttpServerConfig ¶ added in v0.16.0
func NewHttpServerConfig(config interface{}) (*HttpServerConfig, error)
type MockHttpClient ¶ added in v0.16.0
type MockHttpClient struct {
// contains filtered or unexported fields
}
MockHttpClient use mosn http protocol and stream control metrics and connection
func (*MockHttpClient) AsyncCall ¶ added in v0.16.0
func (c *MockHttpClient) AsyncCall()
TODO: implement it
func (*MockHttpClient) Close ¶ added in v0.16.0
func (c *MockHttpClient) Close()
Close will close all the connections
func (*MockHttpClient) Stats ¶ added in v0.16.0
func (c *MockHttpClient) Stats() types.ClientStatsReadOnly
func (*MockHttpClient) SyncCall ¶ added in v0.16.0
func (c *MockHttpClient) SyncCall() bool
type MockHttpServer ¶ added in v0.16.0
type MockHttpServer struct {
// contains filtered or unexported fields
}
func (*MockHttpServer) ServeHTTP ¶ added in v0.16.0
func (s *MockHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
Wrap a http server so we can get the metrics info
func (*MockHttpServer) Start ¶ added in v0.16.0
func (s *MockHttpServer) Start()
func (*MockHttpServer) Stats ¶ added in v0.16.0
func (s *MockHttpServer) Stats() types.ServerStatsReadOnly
func (*MockHttpServer) Stop ¶ added in v0.16.0
func (s *MockHttpServer) Stop()
type RequestConfig ¶ added in v0.16.0
type RequestConfig struct { Method string `json:"method"` Header map[string][]string `json:"header"` Body json.RawMessage `json:"body"` Timeout time.Duration `json:"timeout"` // request timeout }
RequestConfig decides what request to send
func (*RequestConfig) BuildRequest ¶ added in v0.16.0
type ResonseConfig ¶ added in v0.16.0
type ResonseConfig struct { Condition *Condition `json:"condition"` CommonBuilder *ResponseBuilder `json:"common_builder"` ErrorBuilder *ResponseBuilder `json:"error_buidler"` }
ResponseConfig decides what response to send. If a request matches the Condition, send a common repsonse. If not, send an error response
func (*ResonseConfig) ServeHTTP ¶ added in v0.16.0
func (cfg *ResonseConfig) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ResponseBuilder ¶
type ResponseBuilder struct { // The response status code StatusCode int `json:"status_code"` // The response header Header map[string][]string `json:"header"` // The repsonse body content Body string `json:"body"` }
func (*ResponseBuilder) Build ¶
func (b *ResponseBuilder) Build(w http.ResponseWriter) (int, error)
type ResponseWriterWrapper ¶
type ResponseWriterWrapper struct { http.ResponseWriter // contains filtered or unexported fields }
ResponseWriterWrapper wraps a response so we can set the metrics
func (*ResponseWriterWrapper) WriteHeader ¶
func (w *ResponseWriterWrapper) WriteHeader(code int)
type StatsListener ¶
type StatsListener struct {
// contains filtered or unexported fields
}
StatsListener wraps a listener so we can set the metrics
func NewStatsListener ¶
func NewStatsListener(ln net.Listener, stats *types.ServerStats) *StatsListener
func (*StatsListener) Addr ¶
func (sl *StatsListener) Addr() net.Addr
func (*StatsListener) Close ¶
func (sl *StatsListener) Close() error
type VerifyConfig ¶
type VerifyConfig struct { ExpectedStatusCode int // if ExepctedHeader is nil, means do not care about header // if ExepctedHeader is exists, means resposne header should contain all the ExpectedHeader // If response header contain keys not in ExpectedHeader, we ignore it. // TODO: support regex ExpectedHeader map[string][]string // if ExpectedBody is nil, means do not care about body // TODO: support regex ExpectedBody []byte // if MaxExpectedRT is zero, means do not care about rt // if MaxExpectedRT is not zero, means response's rt should no more than it MaxExpectedRT time.Duration // if MinExpectedRT is zero means do not care about it // if MinExpectedRT is not zero, means response's rt should more than it MinExpectedRT time.Duration }
VerifyConfig describes what response want
func (*VerifyConfig) Verify ¶
func (c *VerifyConfig) Verify(resp *Response) bool
Click to show internal directories.
Click to hide internal directories.