server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 17 Imported by: ? 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 server is mock-wms: a small HTTP service that behaves like the warehouse system for the test stand.

Input: POST /reservations (reserve the lines of an order), POST /reservations/{external_id}/release (undo it), POST /shipments (ship an order), and GET /reservations?external_id= and GET /shipments?external_id= (lookups). Output: JSON. It writes only to its own schema mock_wms, so that a test can count effects with a query.

A request with an external_id that is already there changes nothing and answers 200 with the stored row (an idempotent receiver). A release is idempotent too: it releases what is there and does nothing for what is not.

A shipment is the fact of the warehouse: it records the quantity that left (the ordered quantity times MOCK_SHIP_QTY_FACTOR) and one SSCC per line, derived from the external id so that the same shipment always has the same labels.

Fault knobs (from the environment, or set by tests): the share of requests that commit and then answer 500, a fixed delay, a business reference prefix that gets a permanent refusal (422; for shipments only, so that a reservation can succeed and be compensated), and the quantity factor of a shipment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) error

Migrate creates the schema and the tables of the mock if they are missing.

func SSCC

func SSCC(externalID string, i int) string

SSCC is the 18 digit label of line i of a shipment: 17 digits taken from SHA-256 of the external id and the line number, and the GS1 check digit (mod 10, weights 3 and 1 from the right). The same shipment always has the same labels.

Types

type Config

type Config struct {
	FailAfterCommitRate float64       // MOCK_FAIL_AFTER_COMMIT_RATE: 0 to 1
	Latency             time.Duration // MOCK_LATENCY_MS
	RejectRefPrefix     string        // MOCK_REJECT_REF_PREFIX: shipments of an order with this prefix get 422
	ShipQtyFactor       string        // MOCK_SHIP_QTY_FACTOR: decimal multiplier of the shipped quantity; "" means 1
}

Config holds the fault knobs.

type Server

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

Server is the HTTP handler of the mock.

func New

func New(pool *pgxpool.Pool, cfg Config) *Server

New builds the server on a pool whose database has the mock schema (see Migrate).

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the routes of the mock.

func (*Server) SetRejectRefPrefix

func (s *Server) SetRejectRefPrefix(prefix string)

SetRejectRefPrefix changes the prefix of business references whose shipment gets a 422.

func (*Server) SetShipQtyFactor

func (s *Server) SetShipQtyFactor(factor string)

SetShipQtyFactor changes the multiplier of the shipped quantity.

Jump to

Keyboard shortcuts

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