contracttest

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package contracttest is the shared suite every verification service adapter passes, like the sending adapters' suite: registration and capabilities, the balance (which sends no address), each of the four results with the service's own code, batches in order, and the errors jobs act on (a rejected key, no credits, rate limits, an outage), against a fake of the service's API that serves recorded answers.

func TestContract(t *testing.T) {
	contracttest.Run(t, contracttest.Suite{Service: "zerobounce", API: fake})
}

The fake reads Env.Mode and the address in the request to choose a recorded answer: the addresses below stand for each result.

Index

Constants

View Source
const (
	ModeOK          = ""
	ModeAuth        = "auth"         // the key is rejected
	ModeNoCredits   = "no_credits"   // the account is empty
	ModeRateLimited = "rate_limited" // 429 or the service's throttle answer
	ModeOutage      = "outage"       // 5xx
)

Modes the fake API simulates.

View Source
const (
	AddrValid      = "valid@contract.test"
	AddrInvalid    = "invalid@contract.test"
	AddrCatchAll   = "catchall@contract.test"
	AddrRole       = "role@contract.test"
	AddrDisposable = "disposable@contract.test"
	AddrUnknown    = "unknown@contract.test"
	// AddrSpamTrap is answered as a spam trap by services that report them.
	AddrSpamTrap = "trap@contract.test"
)

Addresses the fake answers for, one per expected answer.

View Source
const Balance = 36656

Balance is what the fake's balance answer holds.

View Source
const Key = "contract-test-key-7f3a91c2"

Key is the API key the suite connects with.

Variables

This section is empty.

Functions

func Address

func Address(r *http.Request, body string) string

Address returns the address a request asks about: the email query parameter, or the first contract address in the body.

func Run

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

Run runs the suite.

Types

type Env

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

Env is shared between the suite and the fake API.

func (*Env) Mode

func (e *Env) Mode() string

Mode is the simulated failure.

func (*Env) Requests

func (e *Env) Requests() []Recorded

Requests returns what the fake received so far.

type Recorded

type Recorded struct {
	Method, Path, Query string
	Header              http.Header
	Body                string
}

Recorded is one request the fake received.

type Suite

type Suite struct {
	// Service is the registry key.
	Service string
	// API is the fake service: it gets the Env to read the mode.
	API func(env *Env) http.Handler
	// SpamTrap is true when the service reports spam traps.
	SpamTrap bool
}

Suite configures a run.

Jump to

Keyboard shortcuts

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