(t *testing.T)
| 280 | } |
| 281 | |
| 282 | func 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 | |
| 326 | func TestOpenSubscription(t *testing.T) { |
| 327 | ctx := context.Background() |
nothing calls this directly
no test coverage detected