1
1
package chi
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
_ "embed"
7
+ "encoding/json"
6
8
"errors"
7
9
"io"
8
10
"net/http"
@@ -15,7 +17,6 @@ import (
15
17
"github.com/getkin/kin-openapi/openapi3"
16
18
"github.com/getkin/kin-openapi/openapi3filter"
17
19
"github.com/go-chi/chi/v5"
18
- "github.com/oapi-codegen/testutil"
19
20
"github.com/stretchr/testify/assert"
20
21
"github.com/stretchr/testify/require"
21
22
)
@@ -29,8 +30,16 @@ func doGet(t *testing.T, mux http.Handler, rawURL string) *httptest.ResponseReco
29
30
t .Fatalf ("Invalid url: %s" , rawURL )
30
31
}
31
32
32
- response := testutil .NewRequest ().Get (u .RequestURI ()).WithHost (u .Host ).WithAcceptJson ().GoWithHTTPHandler (t , mux )
33
- return response .Recorder
33
+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
34
+ require .NoError (t , err )
35
+
36
+ req .Header .Set ("accept" , "application/json" )
37
+
38
+ rr := httptest .NewRecorder ()
39
+
40
+ mux .ServeHTTP (rr , req )
41
+
42
+ return rr
34
43
}
35
44
36
45
func doPost (t * testing.T , mux http.Handler , rawURL string , jsonBody interface {}) * httptest.ResponseRecorder {
@@ -39,8 +48,19 @@ func doPost(t *testing.T, mux http.Handler, rawURL string, jsonBody interface{})
39
48
t .Fatalf ("Invalid url: %s" , rawURL )
40
49
}
41
50
42
- response := testutil .NewRequest ().Post (u .RequestURI ()).WithHost (u .Host ).WithJsonBody (jsonBody ).GoWithHTTPHandler (t , mux )
43
- return response .Recorder
51
+ data , err := json .Marshal (jsonBody )
52
+ require .NoError (t , err )
53
+
54
+ req , err := http .NewRequest (http .MethodGet , u .String (), bytes .NewReader (data ))
55
+ require .NoError (t , err )
56
+
57
+ req .Header .Set ("content-type" , "application/json" )
58
+
59
+ rr := httptest .NewRecorder ()
60
+
61
+ mux .ServeHTTP (rr , req )
62
+
63
+ return rr
44
64
}
45
65
46
66
func TestOapiRequestValidator (t * testing.T ) {
0 commit comments