(t *testing.T)
| 395 | } |
| 396 | |
| 397 | func TestOpenTopicFromURL(t *testing.T) { |
| 398 | t.Setenv("RABBIT_SERVER_URL", rabbitURL) |
| 399 | |
| 400 | tests := []struct { |
| 401 | label string |
| 402 | URLTemplate string |
| 403 | WantErr bool |
| 404 | }{ |
| 405 | {"valid url", "rabbit://%s", false}, |
| 406 | {"valid url with key name parameter", "rabbit://%s?key_name=foo", false}, |
| 407 | {"invalid url with parameters", "rabbit://%s?param=value", true}, |
| 408 | {"invalid url with key name parameter", "rabbit://%s?key_name=", true}, |
| 409 | } |
| 410 | |
| 411 | for _, test := range tests { |
| 412 | t.Run(test.label, func(t *testing.T) { |
| 413 | conn := mustDialRabbit(t) |
| 414 | _, isFake := conn.(*fakeConnection) |
| 415 | if isFake { |
| 416 | t.Skip("test requires real rabbitmq") |
| 417 | } |
| 418 | |
| 419 | h := &harness{conn: conn} |
| 420 | |
| 421 | ctx := context.Background() |
| 422 | |
| 423 | dt, cleanupTopic, err := h.CreateTopic(ctx, t.Name()) |
| 424 | if err != nil { |
| 425 | t.Fatalf("unable to create topic: %v", err) |
| 426 | } |
| 427 | |
| 428 | t.Cleanup(cleanupTopic) |
| 429 | |
| 430 | exchange := dt.(*topic).exchange |
| 431 | url := fmt.Sprintf(test.URLTemplate, exchange) |
| 432 | |
| 433 | topic, err := pubsub.OpenTopic(ctx, url) |
| 434 | if (err != nil) != test.WantErr { |
| 435 | t.Errorf("%s: got error %v, want error %v", test.URLTemplate, err, test.WantErr) |
| 436 | } |
| 437 | if topic != nil { |
| 438 | topic.Shutdown(ctx) |
| 439 | } |
| 440 | }) |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | func TestOpenSubscriptionFromURL(t *testing.T) { |
| 445 | t.Setenv("RABBIT_SERVER_URL", rabbitURL) |
nothing calls this directly
no test coverage detected