-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_test.go
54 lines (42 loc) · 1011 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package fasthttp_test_test
import (
"github.com/valyala/fasthttp"
"testing"
"github.com/tspn/fasthttp-test"
)
func Handler(ctx *fasthttp.RequestCtx){
ctx.WriteString("example")
}
func API(ctx *fasthttp.RequestCtx){
email := ctx.FormValue("email")
ctx.Write(email)
}
func TestSimpleGETRequest(t *testing.T){
resp, body, errs := fasthttp_test.StartServerOnPort(t, fasthttp_test.GET, "/example", 9000, Handler, nil)
if errs != nil {
for _, err := range errs {
t.Error(err)
}
}
if resp == nil {
t.Error("Response is nil")
}
if body != "example" {
t.Error("expected example but got", body)
}
}
func TestSimpleAPIRequest(t *testing.T){
form := `[email protected]`
resp, body, errs := fasthttp_test.StartServerOnPort(t, fasthttp_test.POST, "/api", 9000, API, form)
if errs != nil {
for _, err := range errs {
t.Error(err)
}
}
if resp == nil {
t.Error("Response is nil")
}
if body != "[email protected]" {
t.Error("expected [email protected] but got", body)
}
}