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

Function TestOpenTopic

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

Source from the content-addressed store, hash-verified

280}
281
282func TestOpenTopic(t *testing.T) {
283 ctx := context.Background()
284 creds, err := setup.FakeGCPCredentials(ctx)
285 if err != nil {
286 t.Fatal(err)
287 }
288 projID, err := gcp.DefaultProjectID(creds)
289 if err != nil {
290 t.Fatal(err)
291 }
292 conn, cleanup, err := Dial(ctx, gcp.CredentialsTokenSource(creds))
293 if err != nil {
294 t.Fatal(err)
295 }
296 defer cleanup()
297 client, err := Client(ctx, projID, conn)
298 if err != nil {
299 t.Fatal(err)
300 }
301 topic := OpenTopic(client, "my-topic", nil)
302 defer topic.Shutdown(ctx)
303 err = topic.Send(ctx, &pubsub.Message{Body: []byte("hello world")})
304 if err == nil {
305 t.Error("got nil, want error")
306 }
307
308 // Repeat with OpenTopicByPath.
309 topic, err = OpenTopicByPath(client, path.Join("projects", string(projID), "topics", "my-topic"), nil)
310 if err != nil {
311 t.Fatal(err)
312 }
313 defer topic.Shutdown(ctx)
314 err = topic.Send(ctx, &pubsub.Message{Body: []byte("hello world")})
315 if err == nil {
316 t.Error("got nil, want error")
317 }
318
319 // Try an invalid path.
320 _, err = OpenTopicByPath(client, "my-topic", nil)
321 if err == nil {
322 t.Error("got nil, want error")
323 }
324}
325
326func TestOpenSubscription(t *testing.T) {
327 ctx := context.Background()

Callers

nothing calls this directly

Calls 10

FakeGCPCredentialsFunction · 0.92
DefaultProjectIDFunction · 0.92
CredentialsTokenSourceFunction · 0.92
ClientFunction · 0.85
SendMethod · 0.80
DialFunction · 0.70
OpenTopicFunction · 0.70
OpenTopicByPathFunction · 0.70
ShutdownMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected