(t *testing.T)
| 442 | } |
| 443 | |
| 444 | func TestOpenSubscriptionFromURL(t *testing.T) { |
| 445 | t.Setenv("RABBIT_SERVER_URL", rabbitURL) |
| 446 | |
| 447 | tests := []struct { |
| 448 | label string |
| 449 | URLTemplate string |
| 450 | WantErr bool |
| 451 | }{ |
| 452 | {"url with no QoS prefetch count", "rabbit://%s", false}, |
| 453 | {"invalid parameters", "rabbit://%s?param=value", true}, |
| 454 | {"valid url with QoS prefetch count", "rabbit://%s?prefetch_count=1024", false}, |
| 455 | {"invalid url with QoS prefetch count", "rabbit://%s?prefetch_count=value", true}, |
| 456 | } |
| 457 | |
| 458 | for _, test := range tests { |
| 459 | t.Run(test.label, func(t *testing.T) { |
| 460 | conn := mustDialRabbit(t) |
| 461 | _, isFake := conn.(*fakeConnection) |
| 462 | if isFake { |
| 463 | t.Skip("test requires real rabbitmq") |
| 464 | } |
| 465 | |
| 466 | h := &harness{conn: conn} |
| 467 | |
| 468 | ctx := context.Background() |
| 469 | |
| 470 | dt, cleanupTopic, err := h.CreateTopic(ctx, t.Name()) |
| 471 | if err != nil { |
| 472 | t.Fatalf("unable to create topic: %v", err) |
| 473 | } |
| 474 | |
| 475 | t.Cleanup(cleanupTopic) |
| 476 | |
| 477 | ds, cleanupSubscription, err := h.CreateSubscription(ctx, dt, t.Name()) |
| 478 | if err != nil { |
| 479 | t.Fatalf("unable to create subscription: %v", err) |
| 480 | } |
| 481 | |
| 482 | t.Cleanup(cleanupSubscription) |
| 483 | |
| 484 | queue := ds.(*subscription).queue |
| 485 | url := fmt.Sprintf(test.URLTemplate, queue) |
| 486 | |
| 487 | sub, err := pubsub.OpenSubscription(ctx, url) |
| 488 | if (err != nil) != test.WantErr { |
| 489 | t.Errorf("%s: got error %v, want error %v", test.URLTemplate, err, test.WantErr) |
| 490 | } |
| 491 | |
| 492 | if sub != nil { |
| 493 | sub.Shutdown(ctx) |
| 494 | } |
| 495 | }) |
| 496 | } |
| 497 | } |
nothing calls this directly
no test coverage detected