Skip to content

Commit d899366

Browse files
authored
Merge pull request #7 from oapi-codegen/chore/testutil
Remove `testutil` dependency
2 parents 601a0bd + efee8ce commit d899366

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/oapi-codegen/echo-middleware
33
go 1.20
44

55
require (
6-
github.com/deepmap/oapi-codegen v1.14.0
76
github.com/getkin/kin-openapi v0.118.0
87
github.com/labstack/echo/v4 v4.11.1
98
github.com/stretchr/testify v1.8.4
@@ -24,6 +23,7 @@ require (
2423
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
2524
github.com/perimeterx/marshmallow v1.1.4 // indirect
2625
github.com/pmezard/go-difflib v1.0.0 // indirect
26+
github.com/ugorji/go/codec v1.2.11 // indirect
2727
github.com/valyala/bytebufferpool v1.0.0 // indirect
2828
github.com/valyala/fasttemplate v1.2.2 // indirect
2929
golang.org/x/crypto v0.12.0 // indirect

go.sum

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/deepmap/oapi-codegen v1.14.0 h1:b51/kQwH69rjN5pu+8j/Q5fUGD/rUclLAcGLQWQwa3E=
6-
github.com/deepmap/oapi-codegen v1.14.0/go.mod h1:QcEpzjVDwJEH3Fq6I7XYkI0M/JwvoL82ToYveaeVMAw=
75
github.com/getkin/kin-openapi v0.118.0 h1:z43njxPmJ7TaPpMSCQb7PN0dEYno4tyBPQcrFdHoLuM=
86
github.com/getkin/kin-openapi v0.118.0/go.mod h1:l5e9PaFUo9fyLJCPGQeXI2ML8c3P8BHOEV2VaAVf/pc=
97
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
@@ -62,10 +60,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
6260
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
6361
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
6462
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
65-
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
6663
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
6764
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
6865
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
66+
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
6967
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
7068
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
7169
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=

oapi_validate_test.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
package echomiddleware
1616

1717
import (
18+
"bytes"
1819
"context"
1920
_ "embed"
21+
"encoding/json"
2022
"errors"
2123
"io"
2224
"net/http"
2325
"net/http/httptest"
2426
"net/url"
2527
"testing"
2628

27-
"github.com/deepmap/oapi-codegen/pkg/testutil"
2829
"github.com/getkin/kin-openapi/openapi3"
2930
"github.com/getkin/kin-openapi/openapi3filter"
3031
"github.com/labstack/echo/v4"
@@ -42,8 +43,18 @@ func doGet(t *testing.T, e *echo.Echo, rawURL string) *httptest.ResponseRecorder
4243
t.Fatalf("Invalid url: %s", rawURL)
4344
}
4445

45-
response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, e)
46-
return response.Recorder
46+
r, err := http.NewRequest(http.MethodGet, u.String(), nil)
47+
if err != nil {
48+
t.Fatalf("Could not construct a request: %s", rawURL)
49+
}
50+
r.Header.Set("accept", "application/json")
51+
r.Header.Set("host", u.Host)
52+
53+
tt := httptest.NewRecorder()
54+
55+
e.ServeHTTP(tt, r)
56+
57+
return tt
4758
}
4859

4960
func doPost(t *testing.T, e *echo.Echo, rawURL string, jsonBody interface{}) *httptest.ResponseRecorder {
@@ -52,8 +63,24 @@ func doPost(t *testing.T, e *echo.Echo, rawURL string, jsonBody interface{}) *ht
5263
t.Fatalf("Invalid url: %s", rawURL)
5364
}
5465

55-
response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, e)
56-
return response.Recorder
66+
body, err := json.Marshal(jsonBody)
67+
if err != nil {
68+
t.Fatalf("Could not marshal request body: %v", err)
69+
}
70+
71+
r, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewReader(body))
72+
if err != nil {
73+
t.Fatalf("Could not construct a request for URL %s: %v", rawURL, err)
74+
}
75+
r.Header.Set("accept", "application/json")
76+
r.Header.Set("content-type", "application/json")
77+
r.Header.Set("host", u.Host)
78+
79+
tt := httptest.NewRecorder()
80+
81+
e.ServeHTTP(tt, r)
82+
83+
return tt
5784
}
5885

5986
func TestOapiRequestValidator(t *testing.T) {

0 commit comments

Comments
 (0)