diff --git a/internal/cmd/backup_test.go b/internal/cmd/backup_test.go index d39cc0a..1f2d0f3 100644 --- a/internal/cmd/backup_test.go +++ b/internal/cmd/backup_test.go @@ -131,7 +131,7 @@ func TestFilterSchemaDefs(t *testing.T) { } } -func TestBackupParseRelsCmdFunc(t *testing.T) { +func TestBackupMustParseV1RelsCmdFunc(t *testing.T) { for _, tt := range []struct { name string filter string @@ -300,13 +300,12 @@ func TestBackupCreateCmdFunc(t *testing.T) { _, err = c.WriteSchema(ctx, &v1.WriteSchemaRequest{Schema: testSchema}) require.NoError(t, err) - testRelString := "test/resource:1#reader@test/user:1" - testRel, _ := tuple.ParseV1Rel(testRelString) + testRel := "test/resource:1#reader@test/user:1" resp, err := c.WriteRelationships(ctx, &v1.WriteRelationshipsRequest{ Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: testRel, + Relationship: tuple.MustParseV1Rel(testRel), }, }, }) @@ -325,7 +324,7 @@ func TestBackupCreateCmdFunc(t *testing.T) { require.Equal(t, testSchema, d.Schema()) rel, err := d.Next() require.NoError(t, err) - require.Equal(t, testRelString, tuple.MustV1StringRelationship(rel)) + require.Equal(t, testRel, tuple.MustV1StringRelationship(rel)) require.Equal(t, resp.WrittenAt.Token, d.ZedToken().Token) } diff --git a/internal/cmd/helpers_test.go b/internal/cmd/helpers_test.go index e6980d5..f7fc04d 100644 --- a/internal/cmd/helpers_test.go +++ b/internal/cmd/helpers_test.go @@ -56,8 +56,7 @@ func createTestBackup(t *testing.T, schema string, relationships []string) strin }() for _, rel := range relationships { - r, err := tuple.ParseV1Rel(rel) - require.NoError(t, err) + r := tuple.MustParseV1Rel(rel) require.NoError(t, avroWriter.Append(r)) } diff --git a/internal/cmd/restorer_test.go b/internal/cmd/restorer_test.go index 412b6f8..061ed81 100644 --- a/internal/cmd/restorer_test.go +++ b/internal/cmd/restorer_test.go @@ -72,9 +72,7 @@ func TestRestorer(t *testing.T) { expectedFilteredRels := make([]string, 0, len(tt.relationships)) for _, rel := range tt.relationships { - v1Relation, err := tuple.ParseV1Rel(rel) - require.NoError(err) - if !hasRelPrefix(v1Relation, tt.prefixFilter) { + if !hasRelPrefix(tuple.MustParseV1Rel(rel), tt.prefixFilter) { continue } @@ -228,10 +226,7 @@ func (m *mockClient) Send(req *v1.BulkImportRelationshipsRequest) error { for i, rel := range req.Relationships { // This is a gosec115 false positive which should be fixed in a future version. uinti, _ := safecast.ToUint(i) - relationString := m.expectedRels[((m.receivedBatches-1)*m.requestedBatchSize)+uinti] - parsedRelation, err := tuple.ParseV1Rel(relationString) - require.NoError(m.t, err) - require.True(m.t, proto.Equal(rel, parsedRelation)) + require.True(m.t, proto.Equal(rel, tuple.MustParseV1Rel(m.expectedRels[((m.receivedBatches-1)*m.requestedBatchSize)+uinti]))) } return nil diff --git a/internal/commands/permission_test.go b/internal/commands/permission_test.go index 639cbe9..30036ac 100644 --- a/internal/commands/permission_test.go +++ b/internal/commands/permission_test.go @@ -129,10 +129,9 @@ func TestLookupResourcesCommand(t *testing.T) { var updates []*v1.RelationshipUpdate for i := 0; i < 10; i++ { - relationship, _ := tuple.ParseV1Rel(fmt.Sprintf("test/resource:%d#reader@test/user:1", i)) updates = append(updates, &v1.RelationshipUpdate{ Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: relationship, + Relationship: tuple.MustParseV1Rel(fmt.Sprintf("test/resource:%d#reader@test/user:1", i)), }) } diff --git a/internal/commands/relationship_test.go b/internal/commands/relationship_test.go index 9c4c8cc..d5dbe66 100644 --- a/internal/commands/relationship_test.go +++ b/internal/commands/relationship_test.go @@ -67,8 +67,7 @@ func TestRelationshipToString(t *testing.T) { } { tt := tt t.Run(tt.rawRel, func(t *testing.T) { - rel, err := tuple.ParseV1Rel(tt.rawRel) - require.NoError(t, err) + rel := tuple.MustParseV1Rel(tt.rawRel) out, err := relationshipToString(rel) require.NoError(t, err) require.Equal(t, tt.expected, out) @@ -154,7 +153,7 @@ func TestArgsToRelationship(t *testing.T) { } } -func TestParseRelationshipLine(t *testing.T) { +func TestMustParseV1RelationshipLine(t *testing.T) { for _, tt := range []struct { input string expected []string @@ -241,12 +240,11 @@ func TestWriteRelationshipsArgs(t *testing.T) { func TestWriteRelationshipCmdFuncFromTTY(t *testing.T) { mock := func(*cobra.Command) (client.Client, error) { - relationship, _ := tuple.ParseV1Rel(`resource:1#view@user:1[cav:{"letters": ["a", "b", "c"]}]`) return &mockClient{t: t, expectedWrites: []*v1.WriteRelationshipsRequest{{ Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: relationship, + Relationship: tuple.MustParseV1Rel(`resource:1#view@user:1[cav:{"letters": ["a", "b", "c"]}]`), }, }, }}}, nil @@ -285,12 +283,11 @@ func TestWriteRelationshipCmdFuncFromTTY(t *testing.T) { func TestWriteRelationshipCmdFuncArgsTakePrecedence(t *testing.T) { mock := func(*cobra.Command) (client.Client, error) { - relationship, _ := tuple.ParseV1Rel("resource:1#viewer@user:1") return &mockClient{t: t, expectedWrites: []*v1.WriteRelationshipsRequest{{ Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: relationship, + Relationship: tuple.MustParseV1Rel("resource:1#viewer@user:1"), }, }, }}}, nil @@ -332,17 +329,15 @@ func TestWriteRelationshipCmdFuncArgsTakePrecedence(t *testing.T) { func TestWriteRelationshipCmdFuncFromStdin(t *testing.T) { mock := func(*cobra.Command) (client.Client, error) { - one, _ := tuple.ParseV1Rel("resource:1#viewer@user:1") - two, _ := tuple.ParseV1Rel("resource:1#viewer@user:2") return &mockClient{t: t, expectedWrites: []*v1.WriteRelationshipsRequest{{ Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: one, + Relationship: tuple.MustParseV1Rel("resource:1#viewer@user:1"), }, { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: two, + Relationship: tuple.MustParseV1Rel("resource:1#viewer@user:2"), }, }, }}}, nil @@ -377,14 +372,12 @@ func TestWriteRelationshipCmdFuncFromStdin(t *testing.T) { func TestWriteRelationshipCmdFuncFromStdinBatch(t *testing.T) { mock := func(*cobra.Command) (client.Client, error) { - one, _ := tuple.ParseV1Rel(`resource:1#viewer@user:1[cav:{"letters": ["a", "b", "c"]}]`) - two, _ := tuple.ParseV1Rel(`resource:1#viewer@user:2[cav:{"letters": ["a", "b", "c"]}]`) return &mockClient{t: t, expectedWrites: []*v1.WriteRelationshipsRequest{ { Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: one, + Relationship: tuple.MustParseV1Rel(`resource:1#viewer@user:1[cav:{"letters": ["a", "b", "c"]}]`), }, }, }, @@ -392,7 +385,7 @@ func TestWriteRelationshipCmdFuncFromStdinBatch(t *testing.T) { Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: two, + Relationship: tuple.MustParseV1Rel(`resource:1#viewer@user:2[cav:{"letters": ["a", "b", "c"]}]`), }, }, }, @@ -428,13 +421,12 @@ func TestWriteRelationshipCmdFuncFromStdinBatch(t *testing.T) { func TestWriteRelationshipCmdFuncFromFailsWithCaveatArg(t *testing.T) { mock := func(*cobra.Command) (client.Client, error) { - relationship, _ := tuple.ParseV1Rel(`resource:1#viewer@user:1[cav:{"letters": ["a", "b", "c"]}]`) return &mockClient{t: t, expectedWrites: []*v1.WriteRelationshipsRequest{ { Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: relationship, + Relationship: tuple.MustParseV1Rel(`resource:1#viewer@user:1[cav:{"letters": ["a", "b", "c"]}]`), }, }, }, @@ -597,22 +589,19 @@ func TestBulkDeleteForcing(t *testing.T) { _, err = c.WriteSchema(ctx, &v1.WriteSchemaRequest{Schema: testSchema}) require.NoError(t, err) - one, _ := tuple.ParseV1Rel("test/resource:1#reader@test/user:1") - two, _ := tuple.ParseV1Rel("test/resource:1#reader@test/user:2") - three, _ := tuple.ParseV1Rel("test/resource:1#reader@test/user:3") _, err = c.WriteRelationships(ctx, &v1.WriteRelationshipsRequest{ Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: one, + Relationship: tuple.MustParseV1Rel("test/resource:1#reader@test/user:1"), }, { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: two, + Relationship: tuple.MustParseV1Rel("test/resource:1#writer@test/user:2"), }, { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: three, + Relationship: tuple.MustParseV1Rel("test/resource:1#writer@test/user:3"), }, }, }) @@ -652,10 +641,9 @@ func TestBulkDeleteManyForcing(t *testing.T) { var updates []*v1.RelationshipUpdate for i := 0; i < 200; i++ { - relationship, _ := tuple.ParseV1Rel(fmt.Sprintf("test/resource:%d#reader@test/user:1", i)) updates = append(updates, &v1.RelationshipUpdate{ Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: relationship, + Relationship: tuple.MustParseV1Rel(fmt.Sprintf("test/resource:%d#reader@test/user:1", i)), }) } _, err = c.WriteRelationships(ctx, &v1.WriteRelationshipsRequest{Updates: updates}) @@ -693,22 +681,19 @@ func TestBulkDeleteNotForcing(t *testing.T) { _, err = c.WriteSchema(ctx, &v1.WriteSchemaRequest{Schema: testSchema}) require.NoError(t, err) - one, _ := tuple.ParseV1Rel("test/resource:1#reader@test/user:1") - two, _ := tuple.ParseV1Rel("test/resource:1#reader@test/user:2") - three, _ := tuple.ParseV1Rel("test/resource:1#reader@test/user:3") _, err = c.WriteRelationships(ctx, &v1.WriteRelationshipsRequest{ Updates: []*v1.RelationshipUpdate{ { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: one, + Relationship: tuple.MustParseV1Rel("test/resource:1#reader@test/user:1"), }, { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: two, + Relationship: tuple.MustParseV1Rel("test/resource:1#writer@test/user:2"), }, { Operation: v1.RelationshipUpdate_OPERATION_TOUCH, - Relationship: three, + Relationship: tuple.MustParseV1Rel("test/resource:1#writer@test/user:3"), }, }, })