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

Function TestOpenSubscription

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

Source from the content-addressed store, hash-verified

329}
330
331func TestOpenSubscription(t *testing.T) {
332 ctx := context.Background()
333 creds, err := setup.FakeGCPCredentials(ctx)
334 if err != nil {
335 t.Fatal(err)
336 }
337 projID, err := gcp.DefaultProjectID(creds)
338 if err != nil {
339 t.Fatal(err)
340 }
341 conn, cleanup, err := Dial(ctx, gcp.CredentialsTokenSource(creds))
342 if err != nil {
343 t.Fatal(err)
344 }
345 defer cleanup()
346 sc, err := SubscriberClient(ctx, conn)
347 if err != nil {
348 t.Fatal(err)
349 }
350 sub := OpenSubscription(sc, projID, "my-subscription", nil)
351 defer sub.Shutdown(ctx)
352 _, err = sub.Receive(ctx)
353 if err == nil {
354 t.Error("got nil, want error")
355 }
356
357 // Repeat with OpenSubscriptionByPath.
358 sub, err = OpenSubscriptionByPath(sc, path.Join("projects", string(projID), "subscriptions", "my-subscription"), nil)
359 if err != nil {
360 t.Fatal(err)
361 }
362 defer sub.Shutdown(ctx)
363 _, err = sub.Receive(ctx)
364 if err == nil {
365 t.Error("got nil, want error")
366 }
367
368 // Try an invalid path.
369 _, err = OpenSubscriptionByPath(sc, "my-subscription", nil)
370 if err == nil {
371 t.Error("got nil, want error")
372 }
373}
374
375func TestOpenTopicFromURL(t *testing.T) {
376 cleanup := setup.FakeGCPDefaultCredentials(t)

Callers

nothing calls this directly

Calls 10

FakeGCPCredentialsFunction · 0.92
DefaultProjectIDFunction · 0.92
CredentialsTokenSourceFunction · 0.92
SubscriberClientFunction · 0.85
ReceiveMethod · 0.80
DialFunction · 0.70
OpenSubscriptionFunction · 0.70
OpenSubscriptionByPathFunction · 0.70
ShutdownMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected