@@ -48,6 +48,34 @@ func TestEndpoint_Handler(t *testing.T) {
4848 }` , rec .Body .String ())
4949 })
5050
51+ t .Run ("GetEndpoint" , func (t * testing.T ) {
52+ t .Parallel ()
53+
54+ rec := httptest .NewRecorder ()
55+
56+ handler := EndpointFunc [EmptyRequest , BasicResponse ](
57+ func (ctx context.Context , req * EmptyRequest ) (* BasicResponse , error ) {
58+ return & BasicResponse {
59+ Message : "Hello Tester" ,
60+ ID : 321 ,
61+ }, nil
62+ },
63+ )
64+
65+ endpoint := NewEndpoint (handler )
66+ req := httptest .NewRequest (http .MethodGet , "/test?name=Tester" , nil )
67+ req .Header .Set ("Content-Type" , "application/json" )
68+
69+ endpoint .Handler ().ServeHTTP (rec , req )
70+
71+ assert .Equal (t , http .StatusOK , rec .Result ().StatusCode )
72+ assert .Equal (t , "application/json; charset=utf-8" , rec .Header ().Get ("Content-Type" ))
73+ assert .JSONEq (t , `{
74+ "message": "Hello Tester",
75+ "id": 321
76+ }` , rec .Body .String ())
77+ })
78+
5179 t .Run ("WithValidation" , func (t * testing.T ) {
5280 t .Parallel ()
5381
@@ -443,6 +471,8 @@ func TestEndpoint_ContextCancellation(t *testing.T) {
443471
444472// Test types and implementations
445473
474+ type EmptyRequest struct {}
475+
446476type BasicRequest struct {
447477 Name string `json:"name"`
448478}
0 commit comments