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

Method CreateTopic

pubsub/gcppubsub/gcppubsub_test.go:63–79  ·  view source on GitHub ↗
(ctx context.Context, testName string)

Source from the content-addressed store, hash-verified

61}
62
63func (h *harness) CreateTopic(ctx context.Context, testName string) (dt driver.Topic, cleanup func(), err error) {
64 // We may encounter topics that were created by a previous test run and were
65 // not properly cleaned up. In such a case delete the existing topic and create
66 // a new topic with a higher topic number (to avoid cool-off issues between
67 // deletion and re-creation).
68 for {
69 topicName := fmt.Sprintf("%s-topic-%d", sanitize(testName), atomic.AddUint32(&h.numTopics, 1))
70 topicPath := fmt.Sprintf("projects/%s/topics/%s", projectID, topicName)
71 dt, cleanup, err := createTopic(ctx, h.pubClient, topicName, topicPath)
72 if err != nil && status.Code(err) == codes.AlreadyExists {
73 // Delete the topic and retry.
74 h.pubClient.DeleteTopic(ctx, &pubsubpb.DeleteTopicRequest{Topic: topicPath})
75 continue
76 }
77 return dt, cleanup, err
78 }
79}
80
81func createTopic(ctx context.Context, pubClient *raw.PublisherClient, topicName, topicPath string) (dt driver.Topic, cleanup func(), err error) {
82 _, err = pubClient.CreateTopic(ctx, &pubsubpb.Topic{Name: topicPath})

Callers

nothing calls this directly

Calls 2

sanitizeFunction · 0.70
createTopicFunction · 0.70

Tested by

no test coverage detected