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 ¶
- type Attributes
- type License
- type Server
- func (s *Server) Client(tb testing.TB, cfg licensing.Config) *licensing.Client
- func (s *Server) Do(tb testing.TB, method, path string, body any) (int, []byte)
- func (s *Server) License(tb testing.TB, policyID string, attrs Attributes) License
- func (s *Server) Policy(tb testing.TB, productID string, attrs Attributes) string
- func (s *Server) Product(tb testing.TB, name string) string
- func (s *Server) ProductToken(tb testing.TB, productID string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attributes ¶
Attributes are JSON:API attributes as the API takes them (camelCase names, Keygen's semantics); the server validates them.
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 ¶
Start runs a server over the PostgreSQL at dsn in a new account; it stops when the test ends.
func (*Server) Client ¶
Client is a licensing client of the server: cfg with APIURL and PublicKey filled in.
func (*Server) Do ¶
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 ¶
License creates a license of the policy with attrs (name, metadata, expiry, ...).
func (*Server) Policy ¶
Policy creates a policy of the product: attrs over the defaults {"name": "lictest policy", "scheme": "ED25519_SIGN"}; answers its id.