Skip to content

Commit

Permalink
fix: empty relationtuple list should not error (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored Feb 9, 2021
1 parent 2f2c885 commit fbcb3e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
5 changes: 1 addition & 4 deletions internal/expand/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package expand

import (
"context"
"errors"

"github.com/ory/herodot"

"github.com/ory/keto/internal/x"

Expand Down Expand Up @@ -53,7 +50,7 @@ func (e *Engine) BuildTree(ctx context.Context, subject relationtuple.Subject, r
},
x.WithToken(nextPage),
)
if errors.Is(err, herodot.ErrNotFound) {
if len(rels) == 0 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
6 changes: 0 additions & 6 deletions internal/persistence/sql/relationtuples.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"strings"
"time"

"github.com/ory/herodot"

"github.com/gobuffalo/pop/v5"

"github.com/pkg/errors"
Expand Down Expand Up @@ -127,10 +125,6 @@ func (p *Persister) GetRelationTuples(ctx context.Context, query *relationtuple.
return nil, x.PageTokenEnd, errors.WithStack(err)
}

if len(res) == 0 {
return nil, x.PageTokenEnd, errors.WithStack(herodot.ErrNotFound)
}

cutOff := 1
nextPageToken := pagination.encodeNextPageToken()
if len(res) <= pagination.Limit {
Expand Down
13 changes: 13 additions & 0 deletions internal/relationtuple/manager_requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,18 @@ func ManagerTest(t *testing.T, m Manager, addNamespace func(context.Context, *te
assert.Len(t, res, 1)
assert.Equal(t, notEncounteredTuples, res)
})

t.Run("case=empty list", func(t *testing.T) {
nspace := t.Name()
addNamespace(context.Background(), t, nspace)

res, nextPage, err := m.GetRelationTuples(context.Background(), &RelationQuery{
Namespace: nspace,
})

assert.NoError(t, err)
assert.Equal(t, res, []*InternalRelationTuple{})
assert.Equal(t, x.PageTokenEnd, nextPage)
})
})
}

0 comments on commit fbcb3e1

Please sign in to comment.