Help us shape the future of Go! Take the 2026 Go Developer Survey

memsender

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package memsender provides an omnimail.Sender that captures messages in memory. It is intended for tests: assert on what an application sent without a mail server, and inject failures to exercise error handling.

s := memsender.New()
app := NewApp(s)
app.SignUp(ctx, "user@example.org")
if s.Len() != 1 || !strings.Contains(s.Last().Text, "/verify?") { ... }

Index

Constants

View Source
const ProviderName = "memory"

ProviderName is reported in SendResult.Provider.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sender

type Sender struct {
	// contains filtered or unexported fields
}

Sender captures messages in memory. It is safe for concurrent use. The zero value is ready to use.

func New

func New() *Sender

New returns an empty Sender.

func (*Sender) FailNext

func (s *Sender) FailNext(err error)

FailNext queues err to be returned by the next valid Send. Each queued error is used once, in order.

func (*Sender) Last

func (s *Sender) Last() *omnimail.Message

Last returns a copy of the most recently captured message, or nil.

func (*Sender) Len

func (s *Sender) Len() int

Len returns the number of captured messages.

func (*Sender) Messages

func (s *Sender) Messages() []*omnimail.Message

Messages returns deep copies of the captured messages in send order.

func (*Sender) Reset

func (s *Sender) Reset()

Reset discards captured messages, queued failures and the fail function.

func (*Sender) Results

func (s *Sender) Results() []omnimail.SendResult

Results returns the SendResults in send order.

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, msg *omnimail.Message) (*omnimail.SendResult, error)

Send validates msg, honors ctx and records a deep copy of msg. Queued failures (FailNext) and the fail function (SetFailFunc) are applied after validation; a failed send records nothing.

func (*Sender) SetFailFunc

func (s *Sender) SetFailFunc(fn func(*omnimail.Message) error)

SetFailFunc installs fn, called for every valid Send (after queued failures). A non-nil return fails the send. Pass nil to remove it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL