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

Function TestOpenSubscriptionFromURL

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

Source from the content-addressed store, hash-verified

402}
403
404func TestOpenSubscriptionFromURL(t *testing.T) {
405 cleanup := setup.FakeGCPDefaultCredentials(t)
406 defer cleanup()
407
408 tests := []struct {
409 URL string
410 WantErr bool
411 }{
412 // OK, short form.
413 {"gcppubsubv2://myproject/mysub", false},
414 // OK, long form.
415 {"gcppubsubv2://projects/myproject/subscriptions/mysub", false},
416 // Invalid parameter.
417 {"gcppubsubv2://myproject/mysub?param=value", true},
418 // Valid max_recv_batch_size
419 {"gcppubsubv2://projects/myproject/subscriptions/mysub?max_recv_batch_size=1", false},
420 // Invalid max_recv_batch_size
421 {"gcppubsubv2://projects/myproject/subscriptions/mysub?max_recv_batch_size=0", true},
422 // Invalid max_recv_batch_size
423 {"gcppubsubv2://projects/myproject/subscriptions/mysub?max_recv_batch_size=1001", true},
424 }
425
426 ctx := context.Background()
427 for _, test := range tests {
428 sub, err := pubsub.OpenSubscription(ctx, test.URL)
429 if (err != nil) != test.WantErr {
430 t.Errorf("%s: got error %v, want error %v", test.URL, err, test.WantErr)
431 }
432 if sub != nil {
433 sub.Shutdown(ctx)
434 }
435 }
436}

Callers

nothing calls this directly

Calls 3

OpenSubscriptionFunction · 0.92
ShutdownMethod · 0.65

Tested by

no test coverage detected