Documentation
¶
Overview ¶
Package fakedokku is the stateful fake dokku server behind sdk/dokkutest.
It lives under internal/ so docket's own engine tests, which sit inside package tasks and so cannot import anything that imports it, can drive it too. It depends on internal/subprocess alone. Callers outside the module use it through sdk/dokkutest, which fills in the property tables from the published catalog; see that package for how to use it.
Index ¶
- Constants
- type Call
- type Handler
- type PortMapping
- type Property
- type PropertyPlugin
- type Server
- func (s *Server) Apps() []string
- func (s *Server) Buildpacks(appName string) []string
- func (s *Server) Calls() []Call
- func (s *Server) Config(appName string) map[string]string
- func (s *Server) Context(ctx context.Context) context.Context
- func (s *Server) Count(line string) int
- func (s *Server) Domains(appName string) []string
- func (s *Server) Fallback(h Handler) *Server
- func (s *Server) GlobalDomains() []string
- func (s *Server) GlobalProperty(plugin, property string) (string, bool)
- func (s *Server) Handle(line string, h Handler) *Server
- func (s *Server) HandlePrefix(prefix string, h Handler) *Server
- func (s *Server) HasApp(name string) bool
- func (s *Server) Lines() []string
- func (s *Server) Links(serviceType, name string) []string
- func (s *Server) Ports(appName string) []PortMapping
- func (s *Server) Property(plugin, appName, property string) (string, bool)
- func (s *Server) ResetCalls()
- func (s *Server) Run(ctx context.Context, in subprocess.ExecCommandInput) (subprocess.ExecCommandResponse, error)
- func (s *Server) Scale(appName string) map[string]int
- func (s *Server) SeedApp(names ...string) *Server
- func (s *Server) SeedBuildpacks(appName string, urls ...string) *Server
- func (s *Server) SeedConfig(appName string, values map[string]string) *Server
- func (s *Server) SeedDatastore(name, defaultImage string) *Server
- func (s *Server) SeedDomains(appName string, domains ...string) *Server
- func (s *Server) SeedGlobalDomains(domains ...string) *Server
- func (s *Server) SeedGlobalProperty(plugin, property, value string) *Server
- func (s *Server) SeedLink(serviceType, name, appName string) *Server
- func (s *Server) SeedPlugin(name, version string) *Server
- func (s *Server) SeedPorts(appName string, mappings ...PortMapping) *Server
- func (s *Server) SeedProperty(plugin, appName, property, value string) *Server
- func (s *Server) SeedScale(appName string, scale map[string]int) *Server
- func (s *Server) SeedService(serviceType, name string, info map[string]string) *Server
- func (s *Server) SeedVersion(version string) *Server
- func (s *Server) ServiceInfo(serviceType, name string) map[string]string
- func (s *Server) Services(serviceType string) []string
- func (s *Server) Unknown() []string
Constants ¶
const DefaultVersion = "0.38.31"
DefaultVersion is the dokku version a new Server reports: the oldest one docket's integration tests run against.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct {
// Command is the program, "dokku" for every command a task sends.
Command string
// Args are the command's arguments as they would have run, unmasked.
Args []string
// Stdin is what the command read on standard input, if anything.
Stdin string
// Unknown is true for a command the Server does not model and no handler
// answered.
Unknown bool
}
Call is one command a Server was sent.
type Handler ¶
type Handler func(ctx context.Context, in subprocess.ExecCommandInput) (subprocess.ExecCommandResponse, error)
Handler answers one command in place of the Server's own model. It has the shape of the runner sdk.ContextWithRunner installs.
func Exit ¶
Exit is a Handler for a command that ran and exited with code, printing stderr, the way the real runner reports it: the response carries the exit code, and the error is an *ExecError with Ran set.
func Unavailable ¶
Unavailable is a Handler for a command that could not run at all, such as a dokku binary that is not installed. A probe reports it as an error rather than as the resource being absent.
type PortMapping ¶
PortMapping is one port mapping, as `ports:report --ports-map-json` reports it.
func (PortMapping) String ¶
func (p PortMapping) String() string
String renders the mapping as the scheme:host:container argument the ports subcommands take.
type Property ¶
Property is one property of a property plugin, and the keys its report carries it under in each scope. An empty key means the property has no form in that scope.
type PropertyPlugin ¶
type PropertyPlugin struct {
// Plugin is the report command's prefix, for example "nginx".
Plugin string
// Subcommand sets and unsets a property, for example "nginx:set" or
// "buildpacks:set-property".
Subcommand string
// Properties are the properties the report always carries, empty when
// unset. A property set under any other name is carried once it is set,
// the way dokku reports a dynamic family such as letsencrypt's
// dns-provider-*.
Properties []Property
}
PropertyPlugin is a dokku plugin whose properties a Server answers for: its `<plugin>:report` reads them and its set subcommand writes them.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a fake dokku that holds state, answers the commands docket's tasks send in the formats they parse, and applies their changes to that state. It records every call, and it fails any command it does not model: the call returns an error naming it and, when the Server was made with a testing.TB, the test fails.
A Server is safe for concurrent use.
func New ¶
func New(t testing.TB, properties []PropertyPlugin) *Server
New returns an empty Server: dokku at DefaultVersion with its core plugins, no apps and no services. t, when not nil, fails the test on a command the Server does not model. properties are the property plugins it answers for.
func (*Server) Buildpacks ¶
Buildpacks returns an app's buildpacks in precedence order.
func (*Server) Config ¶
Config returns a copy of an app's config, or nil when the app does not exist.
func (*Server) Count ¶
Count returns how many commands the Server was sent whose arguments, joined by spaces, are line.
func (*Server) Fallback ¶
Fallback answers every command the Server does not model with h instead of failing it. Calls h answers are not reported by Unknown.
func (*Server) GlobalDomains ¶
GlobalDomains returns the global domains in the order they were added.
func (*Server) GlobalProperty ¶
GlobalProperty returns a plugin property's global value and whether it is set.
func (*Server) Handle ¶
Handle answers every command whose arguments, joined by spaces, are line with h instead of the Server's model, which neither reads nor changes the state. A later handler for the same command wins.
func (*Server) HandlePrefix ¶
HandlePrefix is Handle for every command whose joined arguments start with prefix.
func (*Server) Lines ¶
Lines returns the arguments of every command the Server was sent, each joined by spaces, in order.
func (*Server) Ports ¶
func (s *Server) Ports(appName string) []PortMapping
Ports returns an app's port mappings in the order they were added.
func (*Server) Property ¶
Property returns a plugin property's value on an app and whether it is set.
func (*Server) ResetCalls ¶
func (s *Server) ResetCalls()
ResetCalls forgets every recorded call, leaving the state alone.
func (*Server) Run ¶
func (s *Server) Run(ctx context.Context, in subprocess.ExecCommandInput) (subprocess.ExecCommandResponse, error)
Run answers one command. It is the runner Context installs, exported so a test can wrap it.
func (*Server) SeedBuildpacks ¶
SeedBuildpacks replaces an app's buildpacks, in precedence order, creating the app if needed.
func (*Server) SeedConfig ¶
SeedConfig sets config values on an app, creating the app if needed.
func (*Server) SeedDatastore ¶
SeedDatastore installs a datastore plugin, such as postgres, so the Server answers its service commands. A service created without an image runs defaultImage, a reference such as "postgres:17.2".
func (*Server) SeedDomains ¶
SeedDomains replaces an app's domains, creating the app if needed.
func (*Server) SeedGlobalDomains ¶
SeedGlobalDomains replaces the global domains.
func (*Server) SeedGlobalProperty ¶
SeedGlobalProperty sets a plugin property globally. An empty value leaves it unset.
func (*Server) SeedLink ¶
SeedLink links a service to an app, as `<service>:link` does: the app's config gains the service's DSN. The service and the app must exist.
func (*Server) SeedPlugin ¶
SeedPlugin installs a plugin at version, alongside dokku's core plugins.
func (*Server) SeedPorts ¶
func (s *Server) SeedPorts(appName string, mappings ...PortMapping) *Server
SeedPorts replaces an app's port mappings, creating the app if needed.
func (*Server) SeedProperty ¶
SeedProperty sets a plugin property on an app, creating the app if needed. An empty value leaves it unset.
func (*Server) SeedScale ¶
SeedScale sets process quantities on an app, creating the app if needed. A process type at zero is still reported, the way dokku reports one scaled down.
func (*Server) SeedService ¶
SeedService creates a datastore service, installing its plugin if needed. info sets keys `<service>:info` reports, over the defaults a create writes: "version" is the running image, "dsn" the connection string a link writes into an app's config.
func (*Server) SeedVersion ¶
SeedVersion sets the dokku version the Server reports.
func (*Server) ServiceInfo ¶
ServiceInfo returns a copy of what `<service>:info` reports for a service, or nil when it does not exist.