Skip to content

Commit

Permalink
feat: support patch method
Browse files Browse the repository at this point in the history
  • Loading branch information
kl7sn committed Nov 22, 2022
1 parent ab628d8 commit 0628acd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### react ###
.DS_*
.idea
.vscode
11 changes: 8 additions & 3 deletions gintest/gintest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gintest
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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...)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 0628acd

Please sign in to comment.