Skip to content

Commit e211635

Browse files
authored
fix(pubsub): pipe revision ID in name in DeleteSchemaRevision (#7519)
Since `RevisionID` is deprecated in `DeleteSchemaRevisionRequest`, we need to pass in the revisionID directly in the schema name field instead. This PR also updates the fake to reflect that `RevisionID` is not being used.
1 parent 1e821bd commit e211635

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

‎pubsub/pstest/fake.go‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,20 +1544,26 @@ func (s *GServer) DeleteSchemaRevision(_ context.Context, req *pb.DeleteSchemaRe
15441544
return ret.(*pb.Schema), err
15451545
}
15461546

1547-
if sc, ok := s.schemas[req.Name]; ok {
1548-
if len(sc) == 1 {
1549-
return nil, status.Errorf(codes.InvalidArgument, "cannot delete last revision for schema %q@%q", req.Name, req.RevisionId)
1547+
schemaPath := strings.Split(req.Name, "@")
1548+
if len(schemaPath) != 2 {
1549+
return nil, status.Errorf(codes.InvalidArgument, "could not parse revision ID from schema name: %q", req.Name)
1550+
}
1551+
schemaName := schemaPath[0]
1552+
revID := schemaPath[1]
1553+
schemaRevisions, ok := s.schemas[schemaName]
1554+
if ok {
1555+
if len(schemaRevisions) == 1 {
1556+
return nil, status.Errorf(codes.InvalidArgument, "cannot delete last revision for schema %q", req.Name)
15501557
}
1551-
}
1552-
1553-
schema := s.schemas[req.Name]
1554-
for i, sc := range schema {
1555-
if sc.RevisionId == req.RevisionId {
1556-
s.schemas[req.Name] = append(schema[:i], schema[i+1:]...)
1557-
return schema[len(schema)-1], nil
1558+
for i, sc := range schemaRevisions {
1559+
if sc.RevisionId == revID {
1560+
s.schemas[schemaName] = append(schemaRevisions[:i], schemaRevisions[i+1:]...)
1561+
return schemaRevisions[len(schemaRevisions)-1], nil
1562+
}
15581563
}
15591564
}
1560-
return nil, status.Errorf(codes.NotFound, "schema %q@%q not found", req.Name, req.RevisionId)
1565+
1566+
return nil, status.Errorf(codes.NotFound, "schema %q not found", req.Name)
15611567
}
15621568

15631569
func (s *GServer) DeleteSchema(_ context.Context, req *pb.DeleteSchemaRequest) (*emptypb.Empty, error) {

‎pubsub/schema.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func NewSchemaClient(ctx context.Context, projectID string, opts ...option.Clien
4747

4848
// SchemaConfig is a reference to a PubSub schema.
4949
type SchemaConfig struct {
50-
// The name of the schema populated by the server. This field is read-only.
50+
// Name of the schema.
51+
// Format is `projects/{project}/schemas/{schema}`
5152
Name string
5253

5354
// The type of the schema definition.
@@ -264,10 +265,9 @@ func (c *SchemaClient) RollbackSchema(ctx context.Context, schemaID, revisionID
264265

265266
// DeleteSchemaRevision deletes a specific schema revision.
266267
func (c *SchemaClient) DeleteSchemaRevision(ctx context.Context, schemaID, revisionID string) (*SchemaConfig, error) {
267-
schemaPath := fmt.Sprintf("projects/%s/schemas/%s", c.projectID, schemaID)
268+
schemaPath := fmt.Sprintf("projects/%s/schemas/%s@%s", c.projectID, schemaID, revisionID)
268269
schema, err := c.sc.DeleteSchemaRevision(ctx, &pb.DeleteSchemaRevisionRequest{
269-
Name: schemaPath,
270-
RevisionId: revisionID,
270+
Name: schemaPath,
271271
})
272272
if err != nil {
273273
return nil, err

‎pubsub/schema_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func TestSchema_SchemaRevisions(t *testing.T) {
180180
got = append(got, sc)
181181
}
182182
if gotLen, wantLen := len(got), 2; gotLen != wantLen {
183-
t.Errorf("lListSchemaRevisions() got %d revisions, want: %d", gotLen, wantLen)
183+
t.Errorf("ListSchemaRevisions() got %d revisions, want: %d", gotLen, wantLen)
184184
}
185185
}
186186

0 commit comments

Comments
 (0)