From 0628acd7a3c84b74e5ebdd7e5c5c4c8f4f1b7a62 Mon Sep 17 00:00:00 2001 From: MEX7 Date: Tue, 22 Nov 2022 14:35:31 +0800 Subject: [PATCH] feat: support patch method --- .gitignore | 4 ++++ gintest/gintest.go | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..440f316 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +### react ### +.DS_* +.idea +.vscode diff --git a/gintest/gintest.go b/gintest/gintest.go index 0354250..a400cb3 100644 --- a/gintest/gintest.go +++ b/gintest/gintest.go @@ -3,7 +3,7 @@ package gintest import ( "bytes" "encoding/json" - "io/ioutil" + "io" "net/http" "net/http/httptest" "strings" @@ -54,12 +54,14 @@ func (t *Test) GET(f func(c *gin.Context), call func(m *Mock) error, options ... func (t *Test) POST(f func(c *gin.Context), call func(m *Mock) error, options ...RouteOption) { t.register("POST", f, call, options...) - } func (t *Test) PUT(f func(c *gin.Context), call func(m *Mock) error, options ...RouteOption) { t.register("PUT", f, call, options...) +} +func (t *Test) PATCH(f func(c *gin.Context), call func(m *Mock) error, options ...RouteOption) { + t.register("PATCH", f, call, options...) } func (t *Test) DELETE(f func(c *gin.Context), call func(m *Mock) error, options ...RouteOption) { @@ -113,6 +115,8 @@ func (t *Test) Run() error { t.router.POST(path, value.middleware...) case "PUT": t.router.PUT(path, value.middleware...) + case "PATCH": + t.router.PATCH(path, value.middleware...) case "DELETE": t.router.DELETE(path, value.middleware...) } @@ -160,6 +164,7 @@ func (m *Mock) Exec(options ...MockOption) []byte { if m.query != "" { path = path + "?" + m.query } + var req *http.Request if len(m.jsonBody) != 0 { reader := bytes.NewReader(m.jsonBody) @@ -183,7 +188,7 @@ func (m *Mock) Exec(options ...MockOption) []byte { defer result.Body.Close() // 读取响应body - body, _ := ioutil.ReadAll(result.Body) + body, _ := io.ReadAll(result.Body) return body }