|
8 | 8 | "testing" |
9 | 9 | "time" |
10 | 10 |
|
11 | | - "github.com/stretchr/testify/require" |
12 | 11 | "github.com/ThreeDotsLabs/watermill" |
13 | 12 | "github.com/ThreeDotsLabs/watermill-amqp/v3/pkg/amqp" |
14 | 13 | "github.com/ThreeDotsLabs/watermill-aws/sns" |
@@ -567,58 +566,58 @@ func TestGetErrorClassifier_NilClassifier(t *testing.T) { |
567 | 566 | } |
568 | 567 |
|
569 | 568 | func TestService_Publish(t *testing.T) { |
570 | | -t.Run("nil service", func(t *testing.T) { |
571 | | -var svc *Service |
572 | | -err := svc.Publish(context.Background(), "test.topic", nil) |
573 | | -if err == nil { |
574 | | -t.Fatal("expected error for nil service") |
575 | | -} |
576 | | -}) |
| 569 | + t.Run("nil service", func(t *testing.T) { |
| 570 | + var svc *Service |
| 571 | + err := svc.Publish(context.Background(), "test.topic", nil) |
| 572 | + if err == nil { |
| 573 | + t.Fatal("expected error for nil service") |
| 574 | + } |
| 575 | + }) |
577 | 576 |
|
578 | | -t.Run("nil publisher", func(t *testing.T) { |
579 | | -svc := &Service{} |
580 | | -err := svc.Publish(context.Background(), "test.topic", nil) |
581 | | -if err == nil { |
582 | | -t.Fatal("expected error for nil publisher") |
583 | | -} |
584 | | -}) |
| 577 | + t.Run("nil publisher", func(t *testing.T) { |
| 578 | + svc := &Service{} |
| 579 | + err := svc.Publish(context.Background(), "test.topic", nil) |
| 580 | + if err == nil { |
| 581 | + t.Fatal("expected error for nil publisher") |
| 582 | + } |
| 583 | + }) |
585 | 584 |
|
586 | | -t.Run("empty topic", func(t *testing.T) { |
587 | | -svc := &Service{ |
588 | | -publisher: &testPublisher{}, |
589 | | -} |
590 | | -err := svc.Publish(context.Background(), "", nil) |
591 | | -if err == nil { |
592 | | -t.Fatal("expected error for empty topic") |
593 | | -} |
594 | | -}) |
| 585 | + t.Run("empty topic", func(t *testing.T) { |
| 586 | + svc := &Service{ |
| 587 | + publisher: &testPublisher{}, |
| 588 | + } |
| 589 | + err := svc.Publish(context.Background(), "", nil) |
| 590 | + if err == nil { |
| 591 | + t.Fatal("expected error for empty topic") |
| 592 | + } |
| 593 | + }) |
595 | 594 |
|
596 | | -t.Run("successful publish", func(t *testing.T) { |
597 | | -pub := &testPublisher{} |
598 | | -svc := &Service{ |
599 | | -publisher: pub, |
600 | | -} |
601 | | -msg := message.NewMessage("test-id", []byte("test")) |
602 | | -err := svc.Publish(context.Background(), "test.topic", msg) |
603 | | -if err != nil { |
604 | | -t.Fatalf("unexpected error: %v", err) |
605 | | -} |
606 | | -}) |
| 595 | + t.Run("successful publish", func(t *testing.T) { |
| 596 | + pub := &testPublisher{} |
| 597 | + svc := &Service{ |
| 598 | + publisher: pub, |
| 599 | + } |
| 600 | + msg := message.NewMessage("test-id", []byte("test")) |
| 601 | + err := svc.Publish(context.Background(), "test.topic", msg) |
| 602 | + if err != nil { |
| 603 | + t.Fatalf("unexpected error: %v", err) |
| 604 | + } |
| 605 | + }) |
607 | 606 |
|
608 | | -t.Run("publishes with context", func(t *testing.T) { |
609 | | -pub := &testPublisher{} |
610 | | -svc := &Service{ |
611 | | -publisher: pub, |
612 | | -} |
613 | | -ctx := context.Background() |
614 | | -msg := message.NewMessage("test-id", []byte("test")) |
615 | | -err := svc.Publish(ctx, "test.topic", msg) |
616 | | -if err != nil { |
617 | | -t.Fatalf("unexpected error: %v", err) |
618 | | -} |
619 | | -// Message should have context set |
620 | | -if msg.Context() == nil { |
621 | | -t.Fatal("expected message to have context set") |
622 | | -} |
623 | | -}) |
| 607 | + t.Run("publishes with context", func(t *testing.T) { |
| 608 | + pub := &testPublisher{} |
| 609 | + svc := &Service{ |
| 610 | + publisher: pub, |
| 611 | + } |
| 612 | + ctx := context.Background() |
| 613 | + msg := message.NewMessage("test-id", []byte("test")) |
| 614 | + err := svc.Publish(ctx, "test.topic", msg) |
| 615 | + if err != nil { |
| 616 | + t.Fatalf("unexpected error: %v", err) |
| 617 | + } |
| 618 | + // Message should have context set |
| 619 | + if msg.Context() == nil { |
| 620 | + t.Fatal("expected message to have context set") |
| 621 | + } |
| 622 | + }) |
624 | 623 | } |
0 commit comments