Skip to content

Commit

Permalink
Merge pull request #2172 from josephschorr/memdb-coverage
Browse files Browse the repository at this point in the history
Improve test coverage of memdb datastore with some new rel tests
  • Loading branch information
josephschorr authored Dec 17, 2024
2 parents 397fefb + 68fe232 commit fb5302f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/datastore/memdb/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package memdb

import (
"fmt"
"testing"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"

"github.com/authzed/spicedb/pkg/spiceerrors"
)

func TestErrors(t *testing.T) {
err := NewSerializationMaxRetriesReachedErr(fmt.Errorf("some error"))
spiceerrors.RequireReason(t, v1.ErrorReason_ERROR_REASON_UNSPECIFIED, err, "details")
}
80 changes: 80 additions & 0 deletions pkg/datastore/test/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,19 @@ func QueryRelationshipsWithVariousFiltersTest(t *testing.T, tester DatastoreTest
},
expected: []string{"document:first#viewer@user:tom", "document:second#viewer@user:tom"},
},
{
name: "nonmatching resource type",
filter: datastore.RelationshipsFilter{
OptionalResourceType: "other",
},
relationships: []string{
"document:first#viewer@user:tom",
"document:second#viewer@user:tom",
"folder:secondfolder#viewer@user:tom",
"folder:someotherfolder#viewer@user:tom",
},
expected: []string{},
},
{
name: "resource id",
filter: datastore.RelationshipsFilter{
Expand Down Expand Up @@ -1397,6 +1410,73 @@ func QueryRelationshipsWithVariousFiltersTest(t *testing.T, tester DatastoreTest
"document:first#viewer@user:tom",
},
},
{
name: "multiple subject IDs with subject type",
filter: datastore.RelationshipsFilter{
OptionalSubjectsSelectors: []datastore.SubjectsSelector{
{
OptionalSubjectType: "user",
OptionalSubjectIds: []string{"tom", "fred"},
},
},
},
relationships: []string{
"document:first#viewer@user:tom",
"document:first#viewer@user:fred",
"document:second#viewer@anotheruser:fred#something",
"folder:secondfolder#viewer@anotheruser:sarah",
"folder:someotherfolder#viewer@user:tom",
},
expected: []string{
"document:first#viewer@user:tom",
"document:first#viewer@user:fred",
"folder:someotherfolder#viewer@user:tom",
},
},
{
name: "multiple subject filters",
filter: datastore.RelationshipsFilter{
OptionalSubjectsSelectors: []datastore.SubjectsSelector{
{
OptionalSubjectType: "user",
OptionalSubjectIds: []string{"tom", "fred"},
},
{
OptionalSubjectType: "anotheruser",
OptionalSubjectIds: []string{"tom", "jerry"},
},
},
},
relationships: []string{
"document:first#viewer@user:tom",
"document:first#viewer@user:fred",
"document:second#viewer@anotheruser:fred#something",
"folder:secondfolder#viewer@anotheruser:tom",
"folder:secondfolder#viewer@anotheruser:sarah",
"folder:secondfolder#viewer@anotheruser:jerry",
"folder:someotherfolder#viewer@user:tom",
},
expected: []string{
"document:first#viewer@user:tom",
"document:first#viewer@user:fred",
"folder:someotherfolder#viewer@user:tom",
"folder:secondfolder#viewer@anotheruser:tom",
"folder:secondfolder#viewer@anotheruser:jerry",
},
},
{
name: "relationships with expiration",
filter: datastore.RelationshipsFilter{
OptionalResourceType: "document",
},
relationships: []string{
"document:first#expiring_viewer@user:tom[expiration:2020-01-01T00:00:00Z]",
"document:first#expiring_viewer@user:fred[expiration:2321-01-01T00:00:00Z]",
},
expected: []string{
"document:first#expiring_viewer@user:fred[expiration:2321-01-01T00:00:00Z]",
},
},
}

for _, tc := range tcs {
Expand Down

0 comments on commit fb5302f

Please sign in to comment.