(t *testing.T)
| 402 | } |
| 403 | |
| 404 | func 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 | } |
nothing calls this directly
no test coverage detected