(t *testing.T)
| 649 | } |
| 650 | |
| 651 | func TestMsgPipeline_RcptModifier_Errors(t *testing.T) { |
| 652 | target := testutils.Target{} |
| 653 | mod := testutils.Modifier{ |
| 654 | InstName: "test_modifier", |
| 655 | InitErr: errors.New("1"), |
| 656 | RcptToErr: errors.New("3"), |
| 657 | } |
| 658 | // Added to make sure it is freed properly too. |
| 659 | globalMod := testutils.Modifier{} |
| 660 | sourceMod := testutils.Modifier{} |
| 661 | |
| 662 | d := MsgPipeline{ |
| 663 | msgpipelineCfg: msgpipelineCfg{ |
| 664 | perSource: map[string]sourceBlock{}, |
| 665 | globalModifiers: modify.Group{Modifiers: []module.Modifier{&globalMod}}, |
| 666 | defaultSource: sourceBlock{ |
| 667 | modifiers: modify.Group{Modifiers: []module.Modifier{&sourceMod}}, |
| 668 | defaultRcpt: &rcptBlock{ |
| 669 | modifiers: modify.Group{Modifiers: []module.Modifier{&mod}}, |
| 670 | targets: []module.DeliveryTarget{&target}, |
| 671 | }, |
| 672 | }, |
| 673 | }, |
| 674 | Log: testutils.Logger(t, "msgpipeline"), |
| 675 | } |
| 676 | |
| 677 | t.Run("init err", func(t *testing.T) { |
| 678 | _, err := testutils.DoTestDeliveryErr(t, &d, "sender@example.com", []string{"rcpt1@example.com", "rcpt2@example.com"}) |
| 679 | if err == nil { |
| 680 | t.Fatal("expected error") |
| 681 | } |
| 682 | }) |
| 683 | |
| 684 | mod.InitErr = nil |
| 685 | |
| 686 | // MailFromErr test is inapplicable since RewriteSender is not called for per-rcpt |
| 687 | // modifiers. |
| 688 | |
| 689 | t.Run("rcpt to err", func(t *testing.T) { |
| 690 | _, err := testutils.DoTestDeliveryErr(t, &d, "sender@example.com", []string{"rcpt1@example.com", "rcpt2@example.com"}) |
| 691 | if err == nil { |
| 692 | t.Fatal("expected error") |
| 693 | } |
| 694 | }) |
| 695 | |
| 696 | mod.RcptToErr = nil |
| 697 | |
| 698 | // BodyErr test is inapplicable since RewriteBody is not called for per-rcpt |
| 699 | // modifiers. |
| 700 | |
| 701 | t.Run("no err", func(t *testing.T) { |
| 702 | testutils.DoTestDelivery(t, &d, "sender@example.com", []string{"rcpt1@example.com", "rcpt2@example.com"}) |
| 703 | }) |
| 704 | |
| 705 | if mod.UnclosedStates != 0 || globalMod.UnclosedStates != 0 || sourceMod.UnclosedStates != 0 { |
| 706 | t.Fatalf("modifier state objects leak or double-closed, counters: %d, %d, %d", |
| 707 | mod.UnclosedStates, globalMod.UnclosedStates, sourceMod.UnclosedStates) |
| 708 | } |
nothing calls this directly
no test coverage detected