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

Function TestOpenTopicFromURL

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

OpenTopicFunction · 0.92
ShutdownMethod · 0.65

Tested by

no test coverage detected