Skip to content

Commit c449b51

Browse files
committed
update
1 parent e8ed369 commit c449b51

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

defaults/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package defaults
22

33
import (
44
"context"
5+
"net/http"
56
"sync"
67

78
"github.com/webx-top/echo"
@@ -34,6 +35,17 @@ func NewMockContext(args ...*echo.Echo) echo.Context {
3435
return echo.NewContext(mock.NewRequest(), mock.NewResponse(), e)
3536
}
3637

38+
func NewMockContextWithContext(ctx context.Context, args ...*echo.Echo) echo.Context {
39+
var e *echo.Echo
40+
if len(args) > 0 {
41+
e = args[0]
42+
} else {
43+
e = Default
44+
}
45+
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, `/`, nil)
46+
return echo.NewContext(mock.NewRequest(req), mock.NewResponse(), e)
47+
}
48+
3749
func IsMockContext(c echo.Context) bool {
3850
_, ok := c.Request().(*mock.Request)
3951
if !ok {

0 commit comments

Comments
 (0)