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

Function TestOpenTopicFromURL

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

Source from the content-addressed store, hash-verified

373}
374
375func TestOpenTopicFromURL(t *testing.T) {
376 cleanup := setup.FakeGCPDefaultCredentials(t)
377 defer cleanup()
378
379 tests := []struct {
380 URL string
381 WantErr bool
382 }{
383 // OK, short form.
384 {"gcppubsub://myproject/mytopic", false},
385 // OK, long form.
386 {"gcppubsub://projects/myproject/topic/mytopic", false},
387 // Invalid parameter.
388 {"gcppubsub://myproject/mytopic?param=value", true},
389 // Valid max_send_batch_size
390 {"gcppubsub://projects/mytopic?max_send_batch_size=1", false},
391 // Invalid max_send_batch_size
392 {"gcppubsub://projects/mytopic?max_send_batch_size=0", true},
393 // Invalid max_send_batch_size
394 {"gcppubsub://projects/mytopic?max_send_batch_size=1001", true},
395 }
396
397 ctx := context.Background()
398 for _, test := range tests {
399 topic, err := pubsub.OpenTopic(ctx, test.URL)
400 if (err != nil) != test.WantErr {
401 t.Errorf("%s: got error %v, want error %v", test.URL, err, test.WantErr)
402 }
403 if topic != nil {
404 topic.Shutdown(ctx)
405 }
406 }
407}
408
409func TestOpenSubscriptionFromURL(t *testing.T) {
410 cleanup := setup.FakeGCPDefaultCredentials(t)

Callers

nothing calls this directly

Calls 3

OpenTopicFunction · 0.92
ShutdownMethod · 0.65

Tested by

no test coverage detected