Skip to content

Commit

Permalink
A lot of reworking tests. Most of them pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
wscalf committed Sep 5, 2024
1 parent 4b7f904 commit 9677d97
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 54 deletions.
66 changes: 41 additions & 25 deletions internal/data/spicedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,17 @@ func TestWriteAndReadBackRelationships(t *testing.T) {
return
}

container.WaitForQuantizationInterval()

readRelChan, _, err := spiceDbRepo.ReadRelationships(ctx, &apiV1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &apiV1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
}, 0, "")

Expand Down Expand Up @@ -251,13 +255,17 @@ func TestWriteReadBackDeleteAndReadBackRelationships(t *testing.T) {
return
}

container.WaitForQuantizationInterval()

readRelChan, _, err := spiceDbRepo.ReadRelationships(ctx, &apiV1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &apiV1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
}, 0, "")

Expand All @@ -269,26 +277,32 @@ func TestWriteReadBackDeleteAndReadBackRelationships(t *testing.T) {
assert.Equal(t, 1, len(readrels))

err = spiceDbRepo.DeleteRelationships(ctx, &apiV1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &apiV1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
})

if !assert.NoError(t, err) {
return
}

container.WaitForQuantizationInterval()

readRelChan, _, err = spiceDbRepo.ReadRelationships(ctx, &apiV1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &apiV1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
}, 0, "")

Expand Down Expand Up @@ -359,12 +373,14 @@ func TestSpiceDbRepository_CheckPermission(t *testing.T) {

//Remove // role_binding:rb_test#subject@user:bob
err = spiceDbRepo.DeleteRelationships(ctx, &apiV1beta1.RelationTupleFilter{
ResourceId: pointerize("rb_test"),
ResourceType: pointerize("rbac/role_binding"),
Relation: pointerize("subject"),
ResourceId: pointerize("rb_test"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("role_binding"),
Relation: pointerize("subject"),
SubjectFilter: &apiV1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
})
if !assert.NoError(t, err) {
Expand Down
78 changes: 49 additions & 29 deletions internal/service/relationships_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ func TestRelationshipsService_CreateRelationships(t *testing.T) {
_, err = relationshipsService.CreateTuples(ctx, req)
assert.NoError(t, err)

container.WaitForQuantizationInterval()

readReq := &v1beta1.ReadTuplesRequest{Filter: &v1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &v1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
},
}
Expand Down Expand Up @@ -101,13 +105,17 @@ func TestRelationshipsService_CreateRelationshipsWithTouchFalse(t *testing.T) {
_, err = relationshipsService.CreateTuples(ctx, req)
assert.NoError(t, err)

container.WaitForQuantizationInterval()

readReq := &v1beta1.ReadTuplesRequest{Filter: &v1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &v1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
},
}
Expand Down Expand Up @@ -202,24 +210,30 @@ func TestRelationshipsService_DeleteRelationships(t *testing.T) {
assert.NoError(t, err)

delreq := &v1beta1.DeleteTuplesRequest{Filter: &v1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &v1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
}}
_, err = relationshipsService.DeleteTuples(ctx, delreq)
assert.NoError(t, err)

container.WaitForQuantizationInterval()

readReq := &v1beta1.ReadTuplesRequest{Filter: &v1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &v1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
},
}
Expand Down Expand Up @@ -282,13 +296,17 @@ func TestRelationshipsService_ReadRelationships(t *testing.T) {
_, err = relationshipsService.CreateTuples(ctx, reqCr)
assert.NoError(t, err)

container.WaitForQuantizationInterval()

req := &v1beta1.ReadTuplesRequest{Filter: &v1beta1.RelationTupleFilter{
ResourceId: pointerize("bob_club"),
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceId: pointerize("bob_club"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &v1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
},
}
Expand Down Expand Up @@ -336,11 +354,13 @@ func TestRelationshipsService_ReadRelationships_Paginated(t *testing.T) {
container.WaitForQuantizationInterval()

req := &v1beta1.ReadTuplesRequest{Filter: &v1beta1.RelationTupleFilter{
ResourceType: pointerize("rbac/group"),
Relation: pointerize("member"),
ResourceNamespace: pointerize("rbac"),
ResourceType: pointerize("group"),
Relation: pointerize("member"),
SubjectFilter: &v1beta1.SubjectFilter{
SubjectId: pointerize("bob"),
SubjectType: pointerize("rbac/user"),
SubjectId: pointerize("bob"),
SubjectNamespace: pointerize("rbac"),
SubjectType: pointerize("user"),
},
},
Pagination: &v1beta1.RequestPagination{
Expand Down

0 comments on commit 9677d97

Please sign in to comment.