contracttest

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contracttest is the shared contract suite every SMS adapter passes (brief §3.1): its manifest and the texts people read in every app language, sending, delivery receipts and inbound messages, signature checks, and the optional capabilities its manifest declares: the account's numbers, webhook registration, opt-out sync, registration status and pricing.

It runs against the adapter's fake (recorded payloads, no network): the fake serves the provider's API in each failure mode and signs webhooks the way the provider would.

Index

Constants

View Source
const (
	ModeOK         = smsfake.ModeOK
	ModeOutage     = smsfake.ModeOutage
	ModeAuth       = smsfake.ModeAuth
	InvalidNumber  = smsfake.InvalidNumber
	LandlineNumber = smsfake.LandlineNumber
)

Modes the fake API answers in, and the numbers it refuses (smsfake: the demo's fakes use them without this test-only package).

View Source
const HookURL = "https://reputecast.contract.test/hooks/sms/contract/0123456789abcdef"

HookURL is where the suite's webhooks are addressed.

Variables

This section is empty.

Functions

func CheckTexts

func CheckTexts(t *testing.T, m sms.Manifest)

CheckTexts checks what people read in a manifest (internal/sms, text.go): the adapter keeps its texts in its own catalog, every text has a message saying what its English says, and the catalog is translated into every app language.

func Run

func Run(t *testing.T, s Suite)

Run runs the suite.

Types

type Env

type Env struct {
	URL string
	// contains filtered or unexported fields
}

Env is a running fake.

func (*Env) Mode

func (e *Env) Mode() string

Mode is the fake's current failure mode.

func (*Env) SetMode

func (e *Env) SetMode(m string)

SetMode switches the fake's failure mode.

type Suite

type Suite struct {
	Adapter string
	// API serves the provider's API from recorded payloads; it reads
	// env.Mode() for failure modes.
	API func(env *Env) http.Handler
	// New opens the adapter on the fake.
	New func(t *testing.T, env *Env) sms.Provider
	// From is the sender the send tests use.
	From string
	// Webhooks are recorded receipts and inbound texts (at least one of
	// each).
	Webhooks []Webhook
	// Tamper changes a signed webhook so its signature no longer matches.
	Tamper func(r *http.Request, body []byte) (*http.Request, []byte)
	// SkipOptOutPush leaves out pushing numbers for adapters whose fake
	// keeps a list it can't be told about (none so far).
	SkipOptOutPush bool
}

Suite describes an adapter under test.

type Webhook

type Webhook struct {
	Name string
	// Request builds the webhook as the provider sends it to url, signed.
	Request func(t *testing.T, env *Env, url string) (*http.Request, []byte)
	Want    []sms.Event
}

Webhook is a recorded webhook and what it must parse into.

Jump to

Keyboard shortcuts

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