From 2e3b3280368244b12745db56cfeab19a7e07993b Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Tue, 28 May 2024 09:53:16 +0200 Subject: [PATCH] Move to non-deprecated `oapi-codegen` packages --- go.mod | 4 ++- go.sum | 8 ++--- pkg/service/api_service.go | 2 +- pkg/service/api_service_test.go | 10 +++---- pkg/service/cluster_test.go | 52 ++++++++++++++++----------------- pkg/service/inventory_test.go | 6 ++-- pkg/service/steward_test.go | 10 +++---- pkg/service/tenant_test.go | 28 +++++++++--------- 8 files changed, 61 insertions(+), 59 deletions(-) diff --git a/go.mod b/go.mod index 207c25d..d52f637 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 07cc8e8..413ac23 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/pkg/service/api_service.go b/pkg/service/api_service.go index ce44abd..8ae5a84 100644 --- a/pkg/service/api_service.go +++ b/pkg/service/api_service.go @@ -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" diff --git a/pkg/service/api_service_test.go b/pkg/service/api_service_test.go index fd45268..7b154f4 100644 --- a/pkg/service/api_service_test.go +++ b/pkg/service/api_service_test.go @@ -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" @@ -256,7 +256,7 @@ 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())) } @@ -264,7 +264,7 @@ func TestHealthz(t *testing.T) { 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) @@ -276,7 +276,7 @@ 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) } @@ -284,7 +284,7 @@ func TestSwaggerUI(t *testing.T) { 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{} diff --git a/pkg/service/cluster_test.go b/pkg/service/cluster_test.go index 8fd73bf..47f3fb2 100644 --- a/pkg/service/cluster_test.go +++ b/pkg/service/cluster_test.go @@ -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" @@ -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) @@ -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) @@ -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) @@ -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) } @@ -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) } @@ -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{} @@ -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) @@ -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{} @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) } @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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{} @@ -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{} diff --git a/pkg/service/inventory_test.go b/pkg/service/inventory_test.go index e6586f5..8d9773b 100644 --- a/pkg/service/inventory_test.go +++ b/pkg/service/inventory_test.go @@ -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" ) @@ -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) } @@ -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) } diff --git a/pkg/service/steward_test.go b/pkg/service/steward_test.go index 10ce6c5..6a31fb6 100644 --- a/pkg/service/steward_test.go +++ b/pkg/service/steward_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/deepmap/oapi-codegen/pkg/testutil" + "github.com/oapi-codegen/testutil" "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -115,7 +115,7 @@ func TestInstallSteward(t *testing.T) { result := testutil.NewRequest(). WithHeader("X-Forwarded-Proto", "https"). Get("/install/steward.json?token="+tc.bootstrapToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusOK, result) manifests := &corev1.List{} err := result.UnmarshalJsonToObject(&manifests) @@ -152,7 +152,7 @@ func TestInstallStewardNoToken(t *testing.T) { result := testutil.NewRequest(). Get("/install/steward.json"). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusBadRequest, result) reason := &api.Reason{} err := result.UnmarshalJsonToObject(reason) @@ -165,7 +165,7 @@ func TestInstallStewardInvalidToken(t *testing.T) { result := testutil.NewRequest(). Get("/install/steward.json?token=NonExistentToken"). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusUnauthorized, result) reason := &api.Reason{} err := result.UnmarshalJsonToObject(reason) @@ -178,7 +178,7 @@ func TestInstallStewardUsedToken(t *testing.T) { result := testutil.NewRequest(). Get("/install/steward.json?token="+clusterB.Status.BootstrapToken.Token). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusUnauthorized, result) reason := &api.Reason{} err := result.UnmarshalJsonToObject(reason) diff --git a/pkg/service/tenant_test.go b/pkg/service/tenant_test.go index 1487745..60b68dc 100644 --- a/pkg/service/tenant_test.go +++ b/pkg/service/tenant_test.go @@ -7,8 +7,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" @@ -23,7 +23,7 @@ func TestListTenants(t *testing.T) { result := testutil.NewRequest(). Get("/tenants/"). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusOK, result) tenants := []api.Tenant{} err := result.UnmarshalJsonToObject(&tenants) @@ -56,7 +56,7 @@ func TestCreateTenant(t *testing.T) { Post("/tenants"). WithJsonBody(newTenant). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusCreated, result) tenant := &api.Tenant{} err := result.UnmarshalJsonToObject(tenant) @@ -115,7 +115,7 @@ func TestCreateTenantWithID(t *testing.T) { Post("/tenants/"). WithHeader(echo.HeaderAuthorization, bearerToken). WithJsonBody(requestBody). - Go(t, e) + GoWithHTTPHandler(t, e) assert.Equal(t, http.StatusCreated, response.Code()) tenant := &api.Tenant{} assert.NoError(t, response.UnmarshalJsonToObject(tenant)) @@ -133,7 +133,7 @@ func TestCreateTenantFail(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) @@ -147,7 +147,7 @@ func TestCreateTenantEmpty(t *testing.T) { result := testutil.NewRequest(). Post("/tenants/"). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusBadRequest, result) reason := &api.Reason{} err := result.UnmarshalJsonToObject(reason) @@ -166,7 +166,7 @@ func TestCreateTenantNoGitURL(t *testing.T) { Post("/tenants/"). WithHeader(echo.HeaderAuthorization, bearerToken). WithJsonBody(newTenant). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusBadRequest, result) reason := &api.Reason{} @@ -181,7 +181,7 @@ func TestTenantDelete(t *testing.T) { result := testutil.NewRequest(). Delete("/tenants/"+tenantA.Name). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusNoContent, result) } @@ -191,7 +191,7 @@ func TestTenantGet(t *testing.T) { result := testutil.NewRequest(). Get("/tenants/"+tenantA.Name). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusOK, result) tenant := &api.Tenant{} err := result.UnmarshalJsonToObject(tenant) @@ -209,7 +209,7 @@ func TestTenantUpdateEmpty(t *testing.T) { result := testutil.NewRequest(). Patch("/tenants/1"). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusBadRequest, result) reason := &api.Reason{} err := result.UnmarshalJsonToObject(reason) @@ -231,7 +231,7 @@ func TestTenantUpdateUnknown(t *testing.T) { WithJsonBody(updateTenant). 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) @@ -260,7 +260,7 @@ func TestTenantUpdate(t *testing.T) { WithJsonBody(updateTenant). WithContentType(api.ContentJSONPatch). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusOK, result) tenant := &api.Tenant{} err := result.UnmarshalJsonToObject(tenant) @@ -288,7 +288,7 @@ func TestTenantUpdateDisplayName(t *testing.T) { WithJsonBody(updateTenant). WithContentType(api.ContentJSONPatch). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, http.StatusOK, result) tenant := &api.Tenant{} err := result.UnmarshalJsonToObject(tenant) @@ -361,7 +361,7 @@ func TestTenantPut(t *testing.T) { Put("/tenants/"+tc.tenant.Id.String()). WithJsonBody(tc.tenant). WithHeader(echo.HeaderAuthorization, bearerToken). - Go(t, e) + GoWithHTTPHandler(t, e) requireHTTPCode(t, tc.code, result) res := &api.Tenant{}