Documentation
¶
Overview ¶
Package smsmock is a dev-only implementation of sms.Sender that ships messages to the hamr dev server's SMS inbox at /__hamr/sms.
The mock does not talk to any provider API. It serializes the sms.Message to JSON and POSTs it to the hamr dev proxy, which stores it in an in-memory inbox viewable at http://<dev-proxy>/__hamr/sms.
Because the wire format is JSON (not a provider API), this mock validates how your application uses the sms.Sender interface — it does not validate your production provider adapter. Catch those bugs with your provider's test credentials or integration tests.
Typical wiring in main.go:
var sender sms.Sender
if os.Getenv("SMS_MOCK") == "true" {
sender = smsmock.New(os.Getenv("HAMR_DEV_URL"))
} else {
sender = myapp.NewRealSender(...)
}
The mock client is safe for concurrent use.
Failure simulation: a recipient number whose digits end in "5550001" (e.g. "+15005550001") causes Send to return ErrInvalidNumber without storing the message; one ending in "5550002" returns ErrUndeliverable. The suffixes use the fictional 555 exchange so real numbers can't match. This lets apps test error paths without configuring anything server-side.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidNumber = errors.New("smsmock: invalid recipient number") ErrUndeliverable = errors.New("smsmock: recipient undeliverable") )
Well-known failure outcomes returned by Send when the message hits a magic recipient number. These wrap the server-side refusal so apps can test error paths deterministically.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a dev-only sms.Sender that POSTs messages to the hamr dev server's /__hamr/sms/ingest endpoint.
func New ¶
New returns a Client that ingests messages at baseURL/__hamr/sms/ingest. baseURL is typically the hamr dev proxy origin (e.g. "http://localhost:3000"). Trailing slashes are stripped. An empty baseURL is accepted but every Send will fail until the client is re-configured.