-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.go
More file actions
51 lines (44 loc) · 1.29 KB
/
helpers.go
File metadata and controls
51 lines (44 loc) · 1.29 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
// Copyright 2022 Sylvain Müller. All rights reserved.
// Mount of this source code is governed by a Apache-2.0 license that can be found
// at https://github.com/fox-toolkit/fox/blob/master/LICENSE.txt.
package fox
import (
"net/http"
)
// NewTestContext returns a new [Router] and its associated [Context], designed only for testing purpose.
func NewTestContext(w http.ResponseWriter, r *http.Request, opts ...GlobalOption) (*Router, *Context) {
f, err := NewRouter(opts...)
if err != nil {
panic(err)
}
tc := newTextContextOnly(f, w, r)
return f, tc
}
// NewTestContextOnly returns a new [Context] designed only for testing purpose.
func NewTestContextOnly(w http.ResponseWriter, r *http.Request, opts ...GlobalOption) *Context {
f, err := NewRouter(opts...)
if err != nil {
panic(err)
}
return newTextContextOnly(f, w, r)
}
func newTextContextOnly(fox *Router, w http.ResponseWriter, r *http.Request) *Context {
tree := fox.getTree()
c := tree.allocateContext()
c.resetNil()
c.reset(w, r)
return c
}
func newTestContext(fox *Router) *Context {
tree := fox.getTree()
c := tree.allocateContext()
c.resetNil()
return c
}
func newResponseWriter(w http.ResponseWriter) ResponseWriter {
return &recorder{
ResponseWriter: w,
size: notWritten,
status: http.StatusOK,
}
}