Skip to content

Commit

Permalink
fix(pubsublite)!: rename TopicPartitions to TopicPartitionCount (#3565)
Browse files Browse the repository at this point in the history
For consistency with the Pub/Sub Lite Java and Python client libraries.
  • Loading branch information
tmdiep committed Jan 15, 2021
1 parent bbc61ed commit 86a4de7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 4 additions & 3 deletions pubsublite/admin.go
Expand Up @@ -110,9 +110,10 @@ func (ac *AdminClient) Topic(ctx context.Context, topic string) (*TopicConfig, e
return protoToTopicConfig(topicpb)
}

// TopicPartitions returns the number of partitions for a topic. A valid topic
// path has the format: "projects/PROJECT_ID/locations/ZONE/topics/TOPIC_ID".
func (ac *AdminClient) TopicPartitions(ctx context.Context, topic string) (int, error) {
// TopicPartitionCount returns the number of partitions for a topic. A valid
// topic path has the format:
// "projects/PROJECT_ID/locations/ZONE/topics/TOPIC_ID".
func (ac *AdminClient) TopicPartitionCount(ctx context.Context, topic string) (int, error) {
if _, err := wire.ParseTopicPath(topic); err != nil {
return 0, err
}
Expand Down
10 changes: 5 additions & 5 deletions pubsublite/admin_test.go
Expand Up @@ -108,10 +108,10 @@ func TestAdminTopicCRUD(t *testing.T) {
t.Errorf("Topic() got: %v\nwant: %v", gotConfig, topicConfig)
}

if gotPartitions, err := admin.TopicPartitions(ctx, topicPath); err != nil {
t.Errorf("TopicPartitions() got err: %v", err)
if gotPartitions, err := admin.TopicPartitionCount(ctx, topicPath); err != nil {
t.Errorf("TopicPartitionCount() got err: %v", err)
} else if wantPartitions := 3; gotPartitions != wantPartitions {
t.Errorf("TopicPartitions() got: %v\nwant: %v", gotPartitions, wantPartitions)
t.Errorf("TopicPartitionCount() got: %v\nwant: %v", gotPartitions, wantPartitions)
}

if err := admin.DeleteTopic(ctx, topicPath); err != nil {
Expand Down Expand Up @@ -397,8 +397,8 @@ func TestAdminValidateResourcePaths(t *testing.T) {
if _, err := admin.Topic(ctx, "INVALID"); err == nil {
t.Errorf("Topic() should fail")
}
if _, err := admin.TopicPartitions(ctx, "INVALID"); err == nil {
t.Errorf("TopicPartitions() should fail")
if _, err := admin.TopicPartitionCount(ctx, "INVALID"); err == nil {
t.Errorf("TopicPartitionCount() should fail")
}
if err := admin.DeleteTopic(ctx, "INVALID"); err == nil {
t.Errorf("DeleteTopic() should fail")
Expand Down
4 changes: 2 additions & 2 deletions pubsublite/integration_test.go
Expand Up @@ -163,10 +163,10 @@ func TestIntegration_ResourceAdminOperations(t *testing.T) {
t.Errorf("Topic() got: -, want: +\n%s", diff)
}

if gotTopicPartitions, err := admin.TopicPartitions(ctx, topicPath); err != nil {
if gotTopicPartitions, err := admin.TopicPartitionCount(ctx, topicPath); err != nil {
t.Errorf("Failed to get topic partitions: %v", err)
} else if gotTopicPartitions != newTopicConfig.PartitionCount {
t.Errorf("TopicPartitions() got: %v, want: %v", gotTopicPartitions, newTopicConfig.PartitionCount)
t.Errorf("TopicPartitionCount() got: %v, want: %v", gotTopicPartitions, newTopicConfig.PartitionCount)
}

topicIt := admin.Topics(ctx, locationPath)
Expand Down

0 comments on commit 86a4de7

Please sign in to comment.