-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbug_test.go
More file actions
61 lines (51 loc) · 1.33 KB
/
bug_test.go
File metadata and controls
61 lines (51 loc) · 1.33 KB
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
55
56
57
58
59
60
61
package gserv
import (
"io"
"net/http"
"testing"
)
// Using .Next in a middleware didn't execute other middlewars
func TestIssue12(t *testing.T) {
s := newServerAndWait(t, "localhost:0")
defer s.Shutdown(0)
s.Use(LogRequests(true))
g := s.SubGroup("", "", func(ctx *Context) Response {
ctx.Set("mw", true)
return nil
})
JSONGet(g, "/ping", func(ctx *Context) (*JSONResponse, error) {
if v, ok := ctx.Get("mw").(bool); !ok || !v {
return RespNotFound.(*JSONResponse), nil
}
return NewJSONResponse(nil), nil
}, false)
resp, err := http.Get("http://" + s.Addrs()[0] + "/ping")
if err != nil {
t.Error(err)
return
}
if resp.StatusCode != 200 {
t.Error("couldn't get the ctx value")
}
}
func TestParamAsFirstInRoute(t *testing.T) {
s := newServerAndWait(t, "localhost:0")
defer s.Shutdown(0)
sub := s.SubGroup("app", "/api/v1/app")
sub.GET("/x/:uid/members", func(ctx *Context) Response {
t.Fatal("wrong func")
return NewJSONResponse(M{"message": "members"})
})
sub.GET("/x/:uid/goals", func(ctx *Context) Response {
return NewJSONResponse(M{"message": "goals"})
})
resp, err := http.Get("http://" + s.Addrs()[0] + "/api/v1/app/x/1034/goals")
if err != nil {
t.Error(err)
return
}
if resp.StatusCode != 200 {
body, _ := io.ReadAll(resp.Body)
t.Error("error", resp.StatusCode, string(body))
}
}