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

Function TestOpenSubscription

pubsub/gcppubsubv2/gcppubsub_test.go:326–368  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

FakeGCPCredentialsFunction · 0.92
DefaultProjectIDFunction · 0.92
CredentialsTokenSourceFunction · 0.92
ClientFunction · 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