-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for relationship filtering on watch API
- Loading branch information
1 parent
8f28907
commit 7dd68a1
Showing
2 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package commands | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" | ||
) | ||
|
||
func TestParseRelationshipFilter(t *testing.T) { | ||
tcs := []struct { | ||
input string | ||
expected *v1.RelationshipFilter | ||
}{ | ||
{ | ||
input: "resourceType:resourceId", | ||
expected: &v1.RelationshipFilter{ | ||
ResourceType: "resourceType", | ||
OptionalResourceId: "resourceId", | ||
}, | ||
}, | ||
{ | ||
input: "resourceType:resourceId%", | ||
expected: &v1.RelationshipFilter{ | ||
ResourceType: "resourceType", | ||
OptionalResourceIdPrefix: "resourceId", | ||
}, | ||
}, | ||
{ | ||
input: "resourceType:resourceId#relation", | ||
expected: &v1.RelationshipFilter{ | ||
ResourceType: "resourceType", | ||
OptionalResourceId: "resourceId", | ||
OptionalRelation: "relation", | ||
}, | ||
}, | ||
{ | ||
input: "resourceType:resourceId#relation@subjectType:subjectId", | ||
expected: &v1.RelationshipFilter{ | ||
ResourceType: "resourceType", | ||
OptionalResourceId: "resourceId", | ||
OptionalRelation: "relation", | ||
OptionalSubjectFilter: &v1.SubjectFilter{ | ||
SubjectType: "subjectType", | ||
OptionalSubjectId: "subjectId", | ||
}, | ||
}, | ||
}, | ||
{ | ||
input: "#relation", | ||
expected: &v1.RelationshipFilter{ | ||
OptionalRelation: "relation", | ||
}, | ||
}, | ||
{ | ||
input: "resourceType#relation", | ||
expected: &v1.RelationshipFilter{ | ||
ResourceType: "resourceType", | ||
OptionalRelation: "relation", | ||
}, | ||
}, | ||
{ | ||
input: ":resourceId#relation", | ||
expected: &v1.RelationshipFilter{ | ||
OptionalResourceId: "resourceId", | ||
OptionalRelation: "relation", | ||
}, | ||
}, | ||
{ | ||
input: ":resourceId%#relation", | ||
expected: &v1.RelationshipFilter{ | ||
OptionalResourceIdPrefix: "resourceId", | ||
OptionalRelation: "relation", | ||
}, | ||
}, | ||
{ | ||
input: "resourceType:resourceId#relation@subjectType:subjectId#somerel", | ||
expected: &v1.RelationshipFilter{ | ||
ResourceType: "resourceType", | ||
OptionalResourceId: "resourceId", | ||
OptionalRelation: "relation", | ||
OptionalSubjectFilter: &v1.SubjectFilter{ | ||
SubjectType: "subjectType", | ||
OptionalSubjectId: "subjectId", | ||
OptionalRelation: &v1.SubjectFilter_RelationFilter{Relation: "somerel"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
input: "@subjectType:subjectId#somerel", | ||
expected: &v1.RelationshipFilter{ | ||
OptionalSubjectFilter: &v1.SubjectFilter{ | ||
SubjectType: "subjectType", | ||
OptionalSubjectId: "subjectId", | ||
OptionalRelation: &v1.SubjectFilter_RelationFilter{Relation: "somerel"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
actual, err := parseRelationshipFilter(tc.input) | ||
if err != nil { | ||
t.Errorf("parseRelationshipFilter(%s) returned error: %v", tc.input, err) | ||
} | ||
if !reflect.DeepEqual(actual, tc.expected) { | ||
t.Errorf("parseRelationshipFilter(%s) = %v, expected %v", tc.input, actual, tc.expected) | ||
} | ||
} | ||
} |