(ctx context.Context, testName string)
| 61 | } |
| 62 | |
| 63 | func (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 | |
| 81 | func 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}) |
nothing calls this directly
no test coverage detected