From 9de69db3e24881a5b58dc8702ae2850a0ae1a411 Mon Sep 17 00:00:00 2001 From: Sergei Kolyshkin Date: Wed, 10 May 2023 16:38:46 +0300 Subject: [PATCH] Fix registry creation method Update `Create` method in `registry` package. Add new fixture and fix related test. Update .gitignore file. --- .gitignore | 1 + pkg/v1/registry/requests.go | 2 +- pkg/v1/registry/testing/fixtures.go | 4 ++++ pkg/v1/registry/testing/requests_test.go | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 6f0f633..db18e01 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .DS_Store *.iml coverage.out +main.go diff --git a/pkg/v1/registry/requests.go b/pkg/v1/registry/requests.go index ef025ba..7c84b9a 100644 --- a/pkg/v1/registry/requests.go +++ b/pkg/v1/registry/requests.go @@ -23,7 +23,7 @@ func Create(ctx context.Context, client *v1.ServiceClient, name string) (*Regist return nil, nil, ErrRegistryNameEmpty } - requestBody, err := json.Marshal(name) + requestBody, err := json.Marshal(CreateOpts{Name: name}) if err != nil { return nil, nil, err } diff --git a/pkg/v1/registry/testing/fixtures.go b/pkg/v1/registry/testing/fixtures.go index 657c55d..25ed0d0 100644 --- a/pkg/v1/registry/testing/fixtures.go +++ b/pkg/v1/registry/testing/fixtures.go @@ -8,6 +8,10 @@ import ( const testRegistryID = "9f3b5b5e-1b5a-4b5c-9b5a-5b5c1b5a4b5c" +const testCreateRegistryRequestRaw = `{ + "name": "test-registry" +}` + const testCreateRegistryResponseRaw = `{ "id": "9f3b5b5e-1b5a-4b5c-9b5a-5b5c1b5a4b5c", "name": "test-registry", diff --git a/pkg/v1/registry/testing/requests_test.go b/pkg/v1/registry/testing/requests_test.go index 62c7409..32d676a 100644 --- a/pkg/v1/registry/testing/requests_test.go +++ b/pkg/v1/registry/testing/requests_test.go @@ -16,10 +16,11 @@ func TestCreate(t *testing.T) { testEnv := testutils.SetupTestEnv() defer testEnv.TearDownTestEnv() - testutils.HandleReqWithoutBody(t, &testutils.HandleReqOpts{ + testutils.HandleReqWithBody(t, &testutils.HandleReqOpts{ Mux: testEnv.Mux, URL: "/api/v1/registries", RawResponse: testCreateRegistryResponseRaw, + RawRequest: testCreateRegistryRequestRaw, Method: http.MethodPost, Status: http.StatusCreated, CallFlag: &endpointCalled,