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