Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh committed Oct 24, 2023
1 parent 75cc3a5 commit a2e803f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
14 changes: 1 addition & 13 deletions core/namespace/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 3 additions & 5 deletions internal/store/postgres/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions internal/store/postgres/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package postgres_test

import (
"context"
"errors"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a2e803f

Please sign in to comment.