Skip to content

Commit

Permalink
Move to non-deprecated oapi-codegen packages (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan authored May 28, 2024
1 parent 1f2f2f6 commit 77806ea
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 59 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ toolchain go1.22.3
require (
github.com/AlekSi/pointer v1.2.0
github.com/cosmtrek/air v1.52.0
github.com/deepmap/oapi-codegen v1.16.2
github.com/deepmap/oapi-codegen/v2 v2.1.0
github.com/getkin/kin-openapi v0.123.0
github.com/go-logr/logr v1.4.2
github.com/hashicorp/golang-lru v1.0.2
github.com/labstack/echo/v4 v4.12.0
github.com/oapi-codegen/echo-middleware v1.0.1
github.com/oapi-codegen/runtime v1.1.1
github.com/oapi-codegen/testutil v1.1.0
github.com/projectsyn/lieutenant-operator v1.6.0
github.com/stretchr/testify v1.9.0
github.com/taion809/haikunator v0.0.0-20150324135039-4e414e676fd1
Expand Down Expand Up @@ -56,6 +57,7 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deepmap/oapi-codegen v1.16.2 h1:xGHx0dNqYfy9gE8a7AVgVM8Sd5oF9SEgePzP+UPAUXI=
github.com/deepmap/oapi-codegen v1.16.2/go.mod h1:rdYoEA2GE+riuZ91DvpmBX9hJbQpuY9wchXpfQ3n+ho=
github.com/deepmap/oapi-codegen/v2 v2.1.0 h1:I/NMVhJCtuvL9x+S2QzZKpSjGi33oDZwPRdemvOZWyQ=
github.com/deepmap/oapi-codegen/v2 v2.1.0/go.mod h1:R1wL226vc5VmCNJUvMyYr3hJMm5reyv25j952zAVXZ8=
github.com/disintegration/gift v1.2.1 h1:Y005a1X4Z7Uc+0gLpSAsKhWi4qLtsdEcMIbbdvdZ6pc=
Expand Down Expand Up @@ -214,10 +212,12 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek=
github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o=
github.com/oapi-codegen/echo-middleware v1.0.1 h1:edYGScq1phCcuDoz9AqA9eHX+tEI1LNL5PL1lkkQh1k=
github.com/oapi-codegen/echo-middleware v1.0.1/go.mod h1:DBQKRn+D/vfXOFbaX5GRwFttoJY64JH6yu+pdt7wU3o=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
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/oapi-codegen/testutil v1.1.0 h1:EufqpNg43acR3qzr3ObhXmWg3Sl2kwtRnUN5GYY4d5g=
github.com/oapi-codegen/testutil v1.1.0/go.mod h1:ttCaYbHvJtHuiyeBF0tPIX+4uhEPTeizXKx28okijLw=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo/v2 v2.17.2 h1:7eMhcy3GimbsA3hEnVKdw/PQM9XN9krpKVXsZdph0/g=
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"net/http"
"strings"

oapimiddleware "github.com/deepmap/oapi-codegen/pkg/middleware"
"github.com/getkin/kin-openapi/openapi3"
"github.com/getkin/kin-openapi/openapi3filter"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
oapimiddleware "github.com/oapi-codegen/echo-middleware"
"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down
10 changes: 5 additions & 5 deletions pkg/service/api_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"testing"
"time"

"github.com/deepmap/oapi-codegen/pkg/testutil"
"github.com/getkin/kin-openapi/openapi3"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/testutil"
synv1alpha1 "github.com/projectsyn/lieutenant-operator/api/v1alpha1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -256,15 +256,15 @@ func rawSetupTest(t *testing.T, obj ...client.Object) (*echo.Echo, client.Client
func TestHealthz(t *testing.T) {
e, _ := setupTest(t)

result := testutil.NewRequest().Get("/healthz").Go(t, e)
result := testutil.NewRequest().Get("/healthz").GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
assert.Equal(t, "ok", string(result.Recorder.Body.String()))
}

func TestOpenAPI(t *testing.T) {
e, _ := setupTest(t)

result := testutil.NewRequest().Get("/openapi.json").Go(t, e)
result := testutil.NewRequest().Get("/openapi.json").GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
swaggerSpec := &openapi3.T{}
err := json.Unmarshal(result.Recorder.Body.Bytes(), swaggerSpec)
Expand All @@ -276,15 +276,15 @@ func TestOpenAPI(t *testing.T) {
func TestSwaggerUI(t *testing.T) {
e, _ := setupTest(t)

result := testutil.NewRequest().Get("/docs").Go(t, e)
result := testutil.NewRequest().Get("/docs").GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
assert.NotEmpty(t, result.Recorder.Body.Bytes)
}

func TestDiscovery(t *testing.T) {
e, _ := setupTest(t)

result := testutil.NewRequest().Get("/").Go(t, e)
result := testutil.NewRequest().Get("/").GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
assert.NotEmpty(t, result.Recorder.Body.Bytes)
metadata := api.Metadata{}
Expand Down
52 changes: 26 additions & 26 deletions pkg/service/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"

"github.com/AlekSi/pointer"
"github.com/deepmap/oapi-codegen/pkg/testutil"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/testutil"
synv1alpha1 "github.com/projectsyn/lieutenant-operator/api/v1alpha1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -25,7 +25,7 @@ func TestListCluster(t *testing.T) {
result := testutil.NewRequest().
Get("/clusters").
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
clusters := make([]api.Cluster, 0)
err := result.UnmarshalJsonToObject(&clusters)
Expand All @@ -46,7 +46,7 @@ func TestListCluster_FilteredByTenant(t *testing.T) {
result := testutil.NewRequest().
Get("/clusters?tenant="+tenantA.Name).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
clusters := make([]api.Cluster, 0)
err := result.UnmarshalJsonToObject(&clusters)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestListCluster_Sort(t *testing.T) {
result := testutil.NewRequest().
Get(fmt.Sprintf("/clusters?sort_by=%s", tc.sortBy)).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
clusters := make([]api.Cluster, 0)
err := result.UnmarshalJsonToObject(&clusters)
Expand All @@ -115,7 +115,7 @@ func TestListClusterMissingBearer(t *testing.T) {

result := testutil.NewRequest().
Get("/clusters").
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
}

Expand All @@ -125,7 +125,7 @@ func TestListClusterWrongToken(t *testing.T) {
result := testutil.NewRequest().
Get("/clusters").
WithHeader(echo.HeaderAuthorization, "asdf").
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
}

Expand Down Expand Up @@ -157,7 +157,7 @@ func TestCreateCluster(t *testing.T) {
Post("/clusters").
WithJsonBody(newCluster).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusCreated, result)

cluster := &api.Cluster{}
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestCreateClusterWithId(t *testing.T) {
Post("/clusters").
WithJsonBody(request).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusCreated, result)
cluster := &api.Cluster{}
err := result.UnmarshalJsonToObject(cluster)
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestCreateClusterInstanceFact(t *testing.T) {
Post("/clusters").
WithJsonBody(newCluster).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusCreated, result)

cluster := &api.Cluster{}
Expand All @@ -251,7 +251,7 @@ func TestCreateClusterInstanceFact(t *testing.T) {
Post("/clusters").
WithJsonBody(newCluster).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusCreated, result)
cluster = &api.Cluster{}
err = result.UnmarshalJsonToObject(cluster)
Expand All @@ -268,7 +268,7 @@ func TestCreateClusterNoJSON(t *testing.T) {
WithJsonContentType().
WithBody([]byte("invalid-body")).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand All @@ -287,7 +287,7 @@ func TestCreateClusterNoTenant(t *testing.T) {
Post("/clusters/").
WithJsonBody(createCluster).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand All @@ -302,7 +302,7 @@ func TestCreateClusterEmpty(t *testing.T) {
Post("/clusters/").
WithJsonContentType().
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand All @@ -316,7 +316,7 @@ func TestClusterDelete(t *testing.T) {
result := testutil.NewRequest().
Delete("/clusters/"+clusterA.Name).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusNoContent, result)
}

Expand All @@ -326,7 +326,7 @@ func TestClusterGet(t *testing.T) {
result := testutil.NewRequest().
Get("/clusters/"+clusterA.Name).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
cluster := &api.Cluster{}
err := result.UnmarshalJsonToObject(cluster)
Expand All @@ -345,7 +345,7 @@ func TestClusterGetNoToken(t *testing.T) {
result := testutil.NewRequest().
Get("/clusters/"+clusterB.Name).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
cluster := &api.Cluster{}
err := result.UnmarshalJsonToObject(cluster)
Expand All @@ -362,7 +362,7 @@ func TestClusterGetNotFound(t *testing.T) {
result := testutil.NewRequest().
Get("/clusters/not-existing").
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusNotFound, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand All @@ -376,7 +376,7 @@ func TestClusterUpdateEmpty(t *testing.T) {
result := testutil.NewRequest().
Patch("/clusters/1").
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand All @@ -396,7 +396,7 @@ func TestClusterUpdateTenant(t *testing.T) {
WithJsonBody(updateCluster).
WithContentType(api.ContentJSONPatch).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand All @@ -418,7 +418,7 @@ func TestClusterUpdateUnknown(t *testing.T) {
WithJsonBody(updateCluster).
WithContentType(api.ContentJSONPatch).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand All @@ -440,7 +440,7 @@ func TestClusterUpdateIllegalDeployKey(t *testing.T) {
WithJsonBody(updateCluster).
WithContentType(api.ContentJSONPatch).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand All @@ -462,7 +462,7 @@ func TestClusterUpdateNotManagedDeployKey(t *testing.T) {
WithJsonBody(updateCluster).
WithContentType(api.ContentJSONPatch).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusBadRequest, result)
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
Expand Down Expand Up @@ -499,7 +499,7 @@ func TestClusterUpdate(t *testing.T) {
WithJsonBody(updateCluster).
WithContentType(api.ContentJSONPatch).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
cluster := &api.Cluster{}
err := result.UnmarshalJsonToObject(cluster)
Expand Down Expand Up @@ -532,7 +532,7 @@ func TestClusterUpdateDisplayName(t *testing.T) {
WithJsonBody(updateCluster).
WithContentType(api.ContentJSONPatch).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusOK, result)
cluster := &api.Cluster{}
err := result.UnmarshalJsonToObject(cluster)
Expand Down Expand Up @@ -613,7 +613,7 @@ func TestClusterPut(t *testing.T) {
Put("/clusters/"+tc.cluster.Id.String()).
WithJsonBody(tc.cluster).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, tc.code, result)

res := &api.Cluster{}
Expand Down Expand Up @@ -649,7 +649,7 @@ func TestClusterPutCreateNameMissmatch(t *testing.T) {
Put("/clusters/c-foo").
WithJsonBody(cluster).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusCreated, result)

res := &api.Cluster{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/url"
"testing"

"github.com/deepmap/oapi-codegen/pkg/testutil"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/testutil"

"github.com/projectsyn/lieutenant-api/pkg/api"
)
Expand All @@ -18,7 +18,7 @@ func TestQueryInventory(t *testing.T) {
result := testutil.NewRequest().
WithHeader(echo.HeaderAuthorization, bearerToken).
Get("/inventory?q="+url.QueryEscape(query)).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusInternalServerError, result)
}

Expand All @@ -36,6 +36,6 @@ func TestUpdateInventory(t *testing.T) {
Post("/inventory").
WithJsonBody(updateInventory).
WithHeader(echo.HeaderAuthorization, bearerToken).
Go(t, e)
GoWithHTTPHandler(t, e)
requireHTTPCode(t, http.StatusInternalServerError, result)
}
Loading

0 comments on commit 77806ea

Please sign in to comment.