lictest

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package lictest runs a real backplane-lic server inside a test's process, for integration tests of what uses the licensing API: the server's own HTTP handler on a loopback port, over a PostgreSQL the caller provides (migrated on start), in an account of its own, so tests share one database and run in parallel. An admin token is seeded; Product, ProductToken, Policy and License build a fixture through the API.

srv := lictest.Start(t, dsn)
product := srv.Product(t, "app")
policy := srv.Policy(t, product, lictest.Attributes{"maxMachines": 1, "floating": false})
license := srv.License(t, policy, lictest.Attributes{"metadata": map[string]any{"plan": "pro"}})
vendor := srv.Client(t, licensing.Config{Token: srv.ProductToken(t, product)})
user := srv.Client(t, licensing.Config{LicenseKey: license.Key})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attributes

type Attributes map[string]any

Attributes are JSON:API attributes as the API takes them (camelCase names, Keygen's semantics); the server validates them.

type License

type License struct {
	ID, Key string
}

License is a created license.

type Server

type Server struct {
	// URL is the API origin (http://127.0.0.1:port): licensing.Config's
	// APIURL. The account is also reachable as /v1/accounts/{AccountID}.
	URL string
	// AccountID and Slug name the server's account.
	AccountID, Slug string
	// AdminToken is a bearer token of the account's admin.
	AdminToken string
	// PublicKey is the account's Ed25519 verify key, hex: licensing.Config's
	// PublicKey, which verifies responses, license files and machine files.
	PublicKey string
}

Server is a running licensing server with its account.

func Start

func Start(tb testing.TB, dsn string) *Server

Start runs a server over the PostgreSQL at dsn in a new account; it stops when the test ends.

func (*Server) Client

func (s *Server) Client(tb testing.TB, cfg licensing.Config) *licensing.Client

Client is a licensing client of the server: cfg with APIURL and PublicKey filled in.

func (*Server) Do

func (s *Server) Do(tb testing.TB, method, path string, body any) (int, []byte)

Do sends an admin request to path (under the account, e.g. "/machines") with an optional JSON:API body and answers the status and body.

func (*Server) License

func (s *Server) License(tb testing.TB, policyID string, attrs Attributes) License

License creates a license of the policy with attrs (name, metadata, expiry, ...).

func (*Server) Policy

func (s *Server) Policy(tb testing.TB, productID string, attrs Attributes) string

Policy creates a policy of the product: attrs over the defaults {"name": "lictest policy", "scheme": "ED25519_SIGN"}; answers its id.

func (*Server) Product

func (s *Server) Product(tb testing.TB, name string) string

Product creates a product named name and answers its id.

func (*Server) ProductToken

func (s *Server) ProductToken(tb testing.TB, productID string) string

ProductToken creates a bearer token of the product (what a vendor-side service authenticates with).

Jump to

Keyboard shortcuts

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