Help us shape the future of Go! Take the 2026 Go Developer Survey

hubtest

package
v0.9.1 Latest Latest
Warning

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

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

Documentation

Overview

Package hubtest is a fake lockhub for the tests of locks: it speaks the lock API v1 (signed requests, tickets, decisions with a cursor) on an httptest server, and lets a test decide tickets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {

	// Pub and Priv are the hub's key; a lock pins Pub.
	Pub  ed25519.PublicKey
	Priv ed25519.PrivateKey
	// contains filtered or unexported fields
}

Hub is a fake lockhub serving one lock instance.

func New

func New(t testing.TB, instance string, lockPub ed25519.PublicKey) *Hub

New starts a hub for instance, whose pinned lock key is lockPub. It stops with the test.

func (*Hub) Answer added in v0.5.0

func (h *Hub) Answer(id string) []byte

Answer is the lock's answer to request id, nil before it answered.

func (*Hub) Close

func (h *Hub) Close()

Close stops the hub (it becomes unreachable).

func (*Hub) Consumed

func (h *Hub) Consumed(id string) bool

Consumed reports whether the lock said ticket id was consumed.

func (*Hub) Decide

func (h *Hub) Decide(id string, out ticket.Outcome, reason string)

Decide records a decision on ticket id, signed with the hub's key.

func (*Hub) DecideWith

func (h *Hub) DecideWith(id string, out ticket.Outcome, reason string, key ed25519.PrivateKey, mod func(*ticket.Decision))

DecideWith is Decide signed with key (nil: the hub's), mod applied to the decision before signing (nil: none).

func (*Hub) Pushed

func (h *Hub) Pushed() int

Pushed is how many tickets the hub accepted.

func (*Hub) RawRequest added in v0.5.0

func (h *Hub) RawRequest(id string, raw []byte)

RawRequest queues raw as a hub request under id, as it is (forged or malformed requests).

func (*Hub) Request added in v0.5.0

func (h *Hub) Request(id string, kind ticket.RequestKind, rk *ticket.RevealKey, mod func(*ticket.HubRequest)) string

Request queues a hub request about ticket id, signed with the hub's key after mod (nil: none), for the lock's next poll, and returns its id. A reveal carries rk.

func (*Hub) Requeue added in v0.5.0

func (h *Hub) Requeue(id string)

Requeue queues request id again, as it was first sent (a replay).

func (*Hub) SetLockKey

func (h *Hub) SetLockKey(pub ed25519.PublicKey)

SetLockKey changes the lock key the hub pinned for the instance.

func (*Hub) SetPushStatus

func (h *Hub) SetPushStatus(code int)

SetPushStatus makes every POST /v1/tickets answer code (0: normal).

func (*Hub) SetWithdrawStatus added in v0.4.0

func (h *Hub) SetWithdrawStatus(id string, code int)

SetWithdrawStatus makes a withdrawal of ticket id answer code (0: the normal 204, recorded).

func (*Hub) Sinces

func (h *Hub) Sinces() []string

Sinces lists the since values of the lock's decision polls.

func (*Hub) Ticket

func (h *Hub) Ticket(id string) []byte

Ticket is the signed ticket id as pushed, nil when not.

func (*Hub) Tickets

func (h *Hub) Tickets() []string

Tickets lists the ids of the tickets pushed.

func (*Hub) URL

func (h *Hub) URL() string

URL is the hub's base URL.

func (*Hub) Withdrawn

func (h *Hub) Withdrawn(id string) (string, bool)

Withdrawn returns the reason ticket id was withdrawn with, and whether.

Jump to

Keyboard shortcuts

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