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 ¶
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).
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 ¶
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.
Types ¶
type Env ¶
type Env struct {
URL string
// contains filtered or unexported fields
}
Env is a running fake.
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.