Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/test/chi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/getkin/kin-openapi v0.124.0
github.com/go-chi/chi/v5 v5.0.10
github.com/oapi-codegen/nethttp-middleware v0.0.0-00010101000000-000000000000
github.com/oapi-codegen/testutil v1.0.0
github.com/stretchr/testify v1.8.4
)

Expand Down
2 changes: 0 additions & 2 deletions internal/test/chi/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/testutil v1.0.0 h1:1GI2IiMMLh2vDHr1OkNacaYU/VaApKdcmfgl4aeXAa8=
github.com/oapi-codegen/testutil v1.0.0/go.mod h1:ttCaYbHvJtHuiyeBF0tPIX+4uhEPTeizXKx28okijLw=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
30 changes: 25 additions & 5 deletions internal/test/chi/oapi_validate_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package chi

import (
"bytes"
"context"
_ "embed"
"encoding/json"
"errors"
"io"
"net/http"
Expand All @@ -15,7 +17,6 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/getkin/kin-openapi/openapi3filter"
"github.com/go-chi/chi/v5"
"github.com/oapi-codegen/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -29,8 +30,16 @@ func doGet(t *testing.T, mux http.Handler, rawURL string) *httptest.ResponseReco
t.Fatalf("Invalid url: %s", rawURL)
}

response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, mux)
return response.Recorder
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
require.NoError(t, err)

req.Header.Set("accept", "application/json")

rr := httptest.NewRecorder()

mux.ServeHTTP(rr, req)

return rr
}

func doPost(t *testing.T, mux http.Handler, rawURL string, jsonBody interface{}) *httptest.ResponseRecorder {
Expand All @@ -39,8 +48,19 @@ func doPost(t *testing.T, mux http.Handler, rawURL string, jsonBody interface{})
t.Fatalf("Invalid url: %s", rawURL)
}

response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, mux)
return response.Recorder
data, err := json.Marshal(jsonBody)
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewReader(data))
require.NoError(t, err)

req.Header.Set("content-type", "application/json")

rr := httptest.NewRecorder()

mux.ServeHTTP(rr, req)

return rr
}

func TestOapiRequestValidator(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion internal/test/gorilla/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/getkin/kin-openapi v0.124.0
github.com/gorilla/mux v1.8.1
github.com/oapi-codegen/nethttp-middleware v0.0.0-00010101000000-000000000000
github.com/oapi-codegen/testutil v1.0.0
github.com/stretchr/testify v1.8.4
)

Expand Down
2 changes: 0 additions & 2 deletions internal/test/gorilla/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/testutil v1.0.0 h1:1GI2IiMMLh2vDHr1OkNacaYU/VaApKdcmfgl4aeXAa8=
github.com/oapi-codegen/testutil v1.0.0/go.mod h1:ttCaYbHvJtHuiyeBF0tPIX+4uhEPTeizXKx28okijLw=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
30 changes: 25 additions & 5 deletions internal/test/gorilla/oapi_validate_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package gorilla

import (
"bytes"
"context"
_ "embed"
"encoding/json"
"errors"
"io"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/oapi-codegen/testutil"
middleware "github.com/oapi-codegen/nethttp-middleware"

"github.com/getkin/kin-openapi/openapi3"
Expand All @@ -29,8 +30,16 @@ func doGet(t *testing.T, mux http.Handler, rawURL string) *httptest.ResponseReco
t.Fatalf("Invalid url: %s", rawURL)
}

response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, mux)
return response.Recorder
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
require.NoError(t, err)

req.Header.Set("accept", "application/json")

rr := httptest.NewRecorder()

mux.ServeHTTP(rr, req)

return rr
}

func doPost(t *testing.T, mux http.Handler, rawURL string, jsonBody interface{}) *httptest.ResponseRecorder {
Expand All @@ -39,8 +48,19 @@ func doPost(t *testing.T, mux http.Handler, rawURL string, jsonBody interface{})
t.Fatalf("Invalid url: %s", rawURL)
}

response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, mux)
return response.Recorder
data, err := json.Marshal(jsonBody)
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewReader(data))
require.NoError(t, err)

req.Header.Set("content-type", "application/json")

rr := httptest.NewRecorder()

mux.ServeHTTP(rr, req)

return rr
}

func TestOapiRequestValidator(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion internal/test/nethttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ replace github.com/oapi-codegen/nethttp-middleware => ../../../
require (
github.com/getkin/kin-openapi v0.124.0
github.com/oapi-codegen/nethttp-middleware v0.0.0-00010101000000-000000000000
github.com/oapi-codegen/testutil v1.0.0
github.com/stretchr/testify v1.8.4
)

Expand Down
2 changes: 0 additions & 2 deletions internal/test/nethttp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/testutil v1.0.0 h1:1GI2IiMMLh2vDHr1OkNacaYU/VaApKdcmfgl4aeXAa8=
github.com/oapi-codegen/testutil v1.0.0/go.mod h1:ttCaYbHvJtHuiyeBF0tPIX+4uhEPTeizXKx28okijLw=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
30 changes: 25 additions & 5 deletions internal/test/nethttp/oapi_validate_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package gorilla

import (
"bytes"
"context"
_ "embed"
"encoding/json"
"errors"
"io"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/oapi-codegen/testutil"
middleware "github.com/oapi-codegen/nethttp-middleware"

"github.com/getkin/kin-openapi/openapi3"
Expand All @@ -28,8 +29,16 @@ func doGet(t *testing.T, mux http.Handler, rawURL string) *httptest.ResponseReco
t.Fatalf("Invalid url: %s", rawURL)
}

response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, mux)
return response.Recorder
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
require.NoError(t, err)

req.Header.Set("accept", "application/json")

rr := httptest.NewRecorder()

mux.ServeHTTP(rr, req)

return rr
}

func doPost(t *testing.T, mux http.Handler, rawURL string, jsonBody interface{}) *httptest.ResponseRecorder {
Expand All @@ -38,8 +47,19 @@ func doPost(t *testing.T, mux http.Handler, rawURL string, jsonBody interface{})
t.Fatalf("Invalid url: %s", rawURL)
}

response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, mux)
return response.Recorder
data, err := json.Marshal(jsonBody)
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewReader(data))
require.NoError(t, err)

req.Header.Set("content-type", "application/json")

rr := httptest.NewRecorder()

mux.ServeHTTP(rr, req)

return rr
}

// use wraps a given http.ServeMux with middleware for execution
Expand Down