smsmock

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
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

func New(baseURL string) *Client

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.

func (*Client) Send

func (c *Client) Send(ctx context.Context, msg sms.Message) (*sms.Result, error)

Send JSON-encodes msg and POSTs it to the mock inbox. It returns the server-assigned Result on success, ErrInvalidNumber/ErrUndeliverable for magic recipient numbers, or a wrapped transport/HTTP error otherwise.

Jump to

Keyboard shortcuts

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