contracttest

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contracttest is the shared suite every store adapter passes, like the sending and payment adapters' (internal/providers/contracttest, internal/payments/contracttest): the registry entry, reading the shop, products with paging and availability, collections, customers with their marketing consent, orders in a range with the landing page's click token, abandoned checkouts, webhooks (subscribe, list, remove), consent write-back, webhook signatures (a bad or tampered one refused) and the recorded payloads' parsing, refused credentials, throttling and an outage — against the adapter's fake of the platform, with no network.

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

Index

Constants

View Source
const (
	// SampleProducts products, SoldOut of them out of stock.
	SampleProducts = 5
	SoldOut        = "Deploy Friday cap"
	// SampleCollections collections.
	SampleCollections = 2
	// SampleOrders orders, RecentOrders of them created at or after Since,
	// one of which arrived with ClickToken in its landing page.
	SampleOrders = 4
	RecentOrders = 3
	ClickToken   = "rcTOKEN123"
	// Subscribed is a customer who accepted marketing; NotSubscribed one
	// who didn't.
	Subscribed    = "grace.liu@example.com"
	NotSubscribed = "theo.martin@example.com"
)

The sample every fake is seeded with (Seed in each adapter's test):

View Source
const CustomerID = "7001"

CustomerID is the sample customer whose consent write-back is tried.

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 valid credentials.
	Open func() (stores.Client, error)
	// Revoke makes the fake refuse the credentials.
	Revoke func()
	// Outage makes the fake answer 5xx; Throttle throttles n calls.
	Outage   func(on bool)
	Throttle func(n int)
	// Secret signs the fake's deliveries; Deliver signs a recorded payload
	// of a kind (EventOrder, EventProduct, EventProductDeleted,
	// EventCustomer, EventCheckout, and EventInventory for an adapter with
	// an InventoryTopic) as the platform would send it.
	Secret  func() string
	Deliver func(kind string) (http.Header, []byte)
	// Since is the creation date the sample's recent orders start at
	// (older ones are before it).
	Since time.Time
}

Env is the adapter's fake store for one test, seeded with the suite's sample (Seed).

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