Documentation ¶
Overview ¶
Package tests provides simple APIs to test you web server, only support servers which based fasthttp.
Example
import ( "testing" "github.com/go-gem/tests" "github.com/valyala/fasthttp" ) func TestFastHTTP(t *testing.T) { contentType := "text/html; charset=utf-8" statusCode := fasthttp.StatusBadRequest respBody := fasthttp.StatusMessage(fasthttp.StatusBadRequest) // Fake server srv := &fasthttp.Server{ Handler: func(ctx *fasthttp.RequestCtx) { ctx.SetContentType(contentType) ctx.SetStatusCode(statusCode) ctx.SetBodyString(respBody) }, } // Create a Test instance. test := tests.New(srv) // Customize request. // See Test struct. test.Url = "/" // Add excepted result. test.Expect(). Status(statusCode). Header("Content-Type", contentType). Body(respBody) // Custom checking function. test.Expect().Custom(func(resp fasthttp.Response) error { // check response. return nil }) // Run test. if err := test.Run(); err != nil { t.Error(err) } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultTimeout DefaultTimeout = 200 * time.Microsecond )
Functions ¶
This section is empty.
Types ¶
type Expect ¶
type Expect []Func
Expect a slice of checking functions.
Click to show internal directories.
Click to hide internal directories.