MCPcopy Create free account
hub / github.com/foxcpp/maddy / TestMsgPipeline_SourceModifier_Errors

Function TestMsgPipeline_SourceModifier_Errors

internal/msgpipeline/modifier_test.go:580–649  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

578}
579
580func TestMsgPipeline_SourceModifier_Errors(t *testing.T) {
581 target := testutils.Target{}
582 mod := testutils.Modifier{
583 InstName: "test_modifier",
584 InitErr: errors.New("1"),
585 MailFromErr: errors.New("2"),
586 RcptToErr: errors.New("3"),
587 BodyErr: errors.New("4"),
588 }
589 // Added to make sure it is freed properly too.
590 globalMod := testutils.Modifier{}
591 d := MsgPipeline{
592 msgpipelineCfg: msgpipelineCfg{
593 perSource: map[string]sourceBlock{},
594 globalModifiers: modify.Group{Modifiers: []module.Modifier{&globalMod}},
595 defaultSource: sourceBlock{
596 modifiers: modify.Group{Modifiers: []module.Modifier{&mod}},
597 defaultRcpt: &rcptBlock{
598 targets: []module.DeliveryTarget{&target},
599 },
600 },
601 },
602 Log: testutils.Logger(t, "msgpipeline"),
603 }
604
605 t.Run("init err", func(t *testing.T) {
606 _, err := testutils.DoTestDeliveryErr(t, &d, "sender@example.com", []string{"rcpt1@example.com", "rcpt2@example.com"})
607 if err == nil {
608 t.Fatal("expected error")
609 }
610 })
611
612 mod.InitErr = nil
613
614 t.Run("mail from err", func(t *testing.T) {
615 _, err := testutils.DoTestDeliveryErr(t, &d, "sender@example.com", []string{"rcpt1@example.com", "rcpt2@example.com"})
616 if err == nil {
617 t.Fatal("expected error")
618 }
619 })
620
621 mod.MailFromErr = nil
622
623 t.Run("rcpt to err", func(t *testing.T) {
624 _, err := testutils.DoTestDeliveryErr(t, &d, "sender@example.com", []string{"rcpt1@example.com", "rcpt2@example.com"})
625 if err == nil {
626 t.Fatal("expected error")
627 }
628 })
629
630 mod.RcptToErr = nil
631
632 t.Run("body err", func(t *testing.T) {
633 _, err := testutils.DoTestDeliveryErr(t, &d, "sender@example.com", []string{"rcpt1@example.com", "rcpt2@example.com"})
634 if err == nil {
635 t.Fatal("expected error")
636 }
637 })

Callers

nothing calls this directly

Calls 4

LoggerFunction · 0.92
DoTestDeliveryErrFunction · 0.92
DoTestDeliveryFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected