contracttest

package
v1.3.1 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: 7 Imported by: 0

Documentation

Overview

Package contracttest is the shared suite every payment adapter passes, like the sending adapters' (internal/providers/contracttest): the catalog entry, the key rules (restricted keys only, secret keys refused before any call), the permission check, the webhook's registration and signature (bad signatures and replays refused), checkout, products and prices, and an outage — against the adapter's fake of the provider's API, with no network.

func TestContract(t *testing.T) {
	contracttest.Run(t, contracttest.Suite{Adapter: "stripe", Env: newEnv})
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

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

Run runs the contract.

Types

type Env

type Env struct {
	// Open connects to the fake with key.
	Open func(key string) (payments.Client, error)
	// Keys the fake knows: a live and a test restricted key, a restricted
	// key that lacks MissingPermission, and one the provider rejects.
	LiveKey, TestKey, MissingKey, RejectedKey string
	MissingPermission                         string
	// SecretKey is an unrestricted secret key of the provider's format.
	SecretKey string
	// Requests counts the calls the fake received.
	Requests func() int
	// Event is a recorded event (raw body) and Sign signs a body with a
	// webhook secret at ts, as the provider's request headers would.
	Event func(t *testing.T, c payments.Client) []byte
	Sign  func(secret string, body []byte, ts time.Time) http.Header
	// Outage makes the fake answer 5xx to every call.
	Outage func()
}

Env is the adapter's fake provider for one test.

type Suite

type Suite struct {
	Adapter string
	Env     func(t *testing.T) *Env
}

Suite describes one adapter.

Jump to

Keyboard shortcuts

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