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

providertest

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: 17 Imported by: 0

Documentation

Overview

Package providertest is the conformance suite for omnimail.Sender implementations. Every provider adapter (SMTP, SES, SendGrid, Gmail, ...) runs it in its own tests against a fake endpoint, so all providers behave the same for addressing, bodies, headers, validation, cancellation and error classification.

An adapter supplies a Harness: the sender under test wired to a fake provider endpoint (an httptest server, an in-process SMTP server, or a capture hook) that records what the provider received and can be told to fail. Then:

func TestConformance(t *testing.T) {
    providertest.RunAll(t, providertest.Config{
        Harness:      newFakeSESHarness(t),
        Provider:     "ses",
        SupportsTags: true,
    })
}

Raw-MIME providers can decode what their endpoint received with DecodeMIME.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeMIME

func DecodeMIME(raw []byte, envelopeRecipients []string) (*omnimail.Message, error)

DecodeMIME decodes a raw RFC 5322 message, as received by a fake SMTP server or a raw-message API endpoint, into an omnimail.Message for comparison by the suite. envelopeRecipients are the SMTP RCPT TO (or API destination) addresses; those not in To or Cc become Bcc. Tags and IdempotencyKey are not part of MIME and are left empty for the caller to fill from the provider request.

func NormalizeBody

func NormalizeBody(s string) string

NormalizeBody converts CRLF and CR line endings to LF and trims trailing line breaks, so bodies compare equal across transports that add a final newline or rewrite line endings.

func RunAll

func RunAll(t *testing.T, cfg Config)

RunAll runs every conformance check as subtests of t.

Types

type Config

type Config struct {
	// Harness is required.
	Harness Harness
	// Provider is the expected SendResult.Provider and Error.Provider.
	// Empty skips those checks.
	Provider string
	// From is the sender used in test messages (default
	// "no-reply@example.com"). Set it when the fake enforces verified
	// senders.
	From omnimail.Address
	// SupportsTags asserts that Message.Tags reach the provider.
	SupportsTags bool
	// SupportsIdempotencyKey asserts that Message.IdempotencyKey reaches the
	// provider.
	SupportsIdempotencyKey bool
	// SupportsSMTPUTF8 asserts that internationalized addresses
	// (non-ASCII local part or domain) are delivered.
	SupportsSMTPUTF8 bool
	// SkipCustomHeaders skips the custom header check for providers that
	// cannot transmit arbitrary headers.
	SkipCustomHeaders bool
	// Timeout bounds each send (default 10s).
	Timeout time.Duration
}

Config configures the suite.

type Harness

type Harness interface {
	// Sender returns the sender under test, configured to talk to the fake
	// endpoint.
	Sender() omnimail.Sender
	// Captured returns the messages the endpoint accepted since the last
	// Reset, in arrival order, decoded back into omnimail.Message form as the
	// provider received them. Bcc must hold envelope recipients that are not
	// in To or Cc. Tags and IdempotencyKey are populated when the provider
	// transmits them. Headers holds custom headers only (it must include a
	// "Bcc" entry if a Bcc header was transmitted, so leaks are detected).
	Captured(t testing.TB) []*omnimail.Message
	// Reset clears captured messages and pending injected failures.
	Reset()
	// InjectFailure arranges for the next send to fail at the endpoint the
	// way the real provider reports a failure of the given kind (an SMTP
	// reply code, an API error code, an HTTP status). It returns false when
	// the kind cannot be simulated, and that check is skipped.
	InjectFailure(kind omnimail.Kind) bool
}

Harness connects the suite to a provider adapter and its fake endpoint. Methods are called from a single test goroutine, except that Sender's result is used concurrently by the concurrency check.

Jump to

Keyboard shortcuts

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