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

Function TestOpenTopic

pubsub/gcppubsub/gcppubsub_test.go:287–329  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

285}
286
287func TestOpenTopic(t *testing.T) {
288 ctx := context.Background()
289 creds, err := setup.FakeGCPCredentials(ctx)
290 if err != nil {
291 t.Fatal(err)
292 }
293 projID, err := gcp.DefaultProjectID(creds)
294 if err != nil {
295 t.Fatal(err)
296 }
297 conn, cleanup, err := Dial(ctx, gcp.CredentialsTokenSource(creds))
298 if err != nil {
299 t.Fatal(err)
300 }
301 defer cleanup()
302 pc, err := PublisherClient(ctx, conn)
303 if err != nil {
304 t.Fatal(err)
305 }
306 topic := OpenTopic(pc, projID, "my-topic", nil)
307 defer topic.Shutdown(ctx)
308 err = topic.Send(ctx, &pubsub.Message{Body: []byte("hello world")})
309 if err == nil {
310 t.Error("got nil, want error")
311 }
312
313 // Repeat with OpenTopicByPath.
314 topic, err = OpenTopicByPath(pc, path.Join("projects", string(projID), "topics", "my-topic"), nil)
315 if err != nil {
316 t.Fatal(err)
317 }
318 defer topic.Shutdown(ctx)
319 err = topic.Send(ctx, &pubsub.Message{Body: []byte("hello world")})
320 if err == nil {
321 t.Error("got nil, want error")
322 }
323
324 // Try an invalid path.
325 _, err = OpenTopicByPath(pc, "my-topic", nil)
326 if err == nil {
327 t.Error("got nil, want error")
328 }
329}
330
331func TestOpenSubscription(t *testing.T) {
332 ctx := context.Background()

Callers

nothing calls this directly

Calls 10

FakeGCPCredentialsFunction · 0.92
DefaultProjectIDFunction · 0.92
CredentialsTokenSourceFunction · 0.92
PublisherClientFunction · 0.85
SendMethod · 0.80
DialFunction · 0.70
OpenTopicFunction · 0.70
OpenTopicByPathFunction · 0.70
ShutdownMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected