From a2e803fc1da3f5d72e597c4e84aff942f24a92e4 Mon Sep 17 00:00:00 2001 From: Muhammad Abduh Date: Tue, 24 Oct 2023 15:40:25 +0700 Subject: [PATCH] fix test --- core/namespace/service.go | 14 +------------- internal/store/postgres/namespace.go | 8 +++----- internal/store/postgres/namespace_test.go | 7 ++++--- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/core/namespace/service.go b/core/namespace/service.go index c5f1e297..c2929105 100644 --- a/core/namespace/service.go +++ b/core/namespace/service.go @@ -161,20 +161,8 @@ func (s *Service) Update(ctx context.Context, ns *Namespace) error { } ctx = s.repository.WithTransaction(ctx) - - existingNamespace, err := s.repository.Get(ctx, ns.ID) - if err != nil { - if err := s.repository.Rollback(ctx, err); err != nil { - return err - } - if errors.As(err, new(NotFoundError)) { - return errors.ErrNotFound.WithMsgf(err.Error()) - } - return err - } - // merge existing labels - for k, v := range existingNamespace.Labels { + for k, v := range encryptedNS.Labels { ns.Labels[k] = v } diff --git a/internal/store/postgres/namespace.go b/internal/store/postgres/namespace.go index cf69e2f8..3cabb07d 100644 --- a/internal/store/postgres/namespace.go +++ b/internal/store/postgres/namespace.go @@ -179,15 +179,13 @@ func (r NamespaceRepository) UpdateLabels(ctx context.Context, id uint64, labels return nil } pgLabels := pgc.StringStringMap(labels) - rows, err := r.client.QueryxContext(ctx, pgc.OpUpdate, r.tableName, namespaceUpdateLabelQuery, id, pgLabels) - if err != nil { - err = pgc.CheckError(err) + var updatedNamespace model.Namespace + if err := r.client.QueryRowxContext(ctx, pgc.OpUpdate, r.tableName, namespaceUpdateLabelQuery, id, pgLabels). + StructScan(&updatedNamespace); err != nil { if errors.Is(err, sql.ErrNoRows) { return namespace.NotFoundError{ID: id} } - return err } - defer rows.Close() return nil } diff --git a/internal/store/postgres/namespace_test.go b/internal/store/postgres/namespace_test.go index 719fda7b..5e3f2dc7 100644 --- a/internal/store/postgres/namespace_test.go +++ b/internal/store/postgres/namespace_test.go @@ -2,7 +2,6 @@ package postgres_test import ( "context" - "errors" "testing" "github.com/google/go-cmp/cmp" @@ -423,8 +422,10 @@ func (s *NamespaceRepositoryTestSuite) TestUpdateLabels() { { Description: "should return error not found if id not found", ID: 1000, - Labels: map[string]string{}, - Err: errors.New("namespace with id 1000 not found"), + Labels: map[string]string{ + "k": "v", + }, + Err: namespace.NotFoundError{ID: 1000}, }, { ID: 1,