MCPcopy Create free account
hub / github.com/google/go-cloud / createTopic

Function createTopic

pubsub/gcppubsubv2/gcppubsub_test.go:69–87  ·  view source on GitHub ↗
(ctx context.Context, client *raw.Client, topicName string)

Source from the content-addressed store, hash-verified

67}
68
69func createTopic(ctx context.Context, client *raw.Client, topicName string) (dt driver.Topic, cleanup func(), err error) {
70 _, err = client.TopicAdminClient.CreateTopic(ctx, &pubsubpb.Topic{Name: topicPath(topicName)})
71 // We may encounter topics that were created by a previous test run and were
72 // not properly cleaned up. In such a case delete the existing topic and create
73 // a new topic with a higher topic number (to avoid cool-off issues between
74 // deletion and re-creation).
75 if err != nil && status.Code(err) == codes.AlreadyExists {
76 deleteTopic(ctx, client, topicName)
77 return createTopic(ctx, client, topicName)
78 }
79 if err != nil {
80 return nil, nil, fmt.Errorf("failed to create topic: %w", err)
81 }
82 dt = openTopic(client.Publisher(topicName))
83 cleanup = func() {
84 deleteTopic(ctx, client, topicName)
85 }
86 return dt, cleanup, nil
87}
88
89func deleteTopic(ctx context.Context, client *raw.Client, topicName string) {
90 _ = client.TopicAdminClient.DeleteTopic(ctx, &pubsubpb.DeleteTopicRequest{

Callers 2

CreateTopicMethod · 0.70
BenchmarkGcpPubSubFunction · 0.70

Calls 4

topicPathFunction · 0.85
deleteTopicFunction · 0.70
openTopicFunction · 0.70
CreateTopicMethod · 0.65

Tested by

no test coverage detected