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

fakedokku

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
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.

func (Call) Line

func (c Call) Line() string

Line returns the call's arguments joined by spaces, the form Count and Handle take.

type Handler

Handler answers one command in place of the Server's own model. It has the shape of the runner sdk.ContextWithRunner installs.

func Exit

func Exit(code int, stderr string) Handler

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 Respond

func Respond(stdout string) Handler

Respond is a Handler that succeeds and prints stdout.

func Unavailable

func Unavailable(err error) Handler

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

type PortMapping struct {
	Scheme    string
	Host      int
	Container int
}

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

type Property struct {
	Name      string
	AppKey    string
	GlobalKey string
}

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) Apps

func (s *Server) Apps() []string

Apps returns the names of the apps that exist, sorted.

func (*Server) Buildpacks

func (s *Server) Buildpacks(appName string) []string

Buildpacks returns an app's buildpacks in precedence order.

func (*Server) Calls

func (s *Server) Calls() []Call

Calls returns every command the Server was sent, in order.

func (*Server) Config

func (s *Server) Config(appName string) map[string]string

Config returns a copy of an app's config, or nil when the app does not exist.

func (*Server) Context

func (s *Server) Context(ctx context.Context) context.Context

Context returns a copy of ctx whose commands go to the Server.

func (*Server) Count

func (s *Server) Count(line string) int

Count returns how many commands the Server was sent whose arguments, joined by spaces, are line.

func (*Server) Domains

func (s *Server) Domains(appName string) []string

Domains returns an app's domains in the order they were added.

func (*Server) Fallback

func (s *Server) Fallback(h Handler) *Server

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

func (s *Server) GlobalDomains() []string

GlobalDomains returns the global domains in the order they were added.

func (*Server) GlobalProperty

func (s *Server) GlobalProperty(plugin, property string) (string, bool)

GlobalProperty returns a plugin property's global value and whether it is set.

func (*Server) Handle

func (s *Server) Handle(line string, h Handler) *Server

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

func (s *Server) HandlePrefix(prefix string, h Handler) *Server

HandlePrefix is Handle for every command whose joined arguments start with prefix.

func (*Server) HasApp

func (s *Server) HasApp(name string) bool

HasApp reports whether an app exists.

func (*Server) Lines

func (s *Server) Lines() []string

Lines returns the arguments of every command the Server was sent, each joined by spaces, in order.

func (s *Server) Links(serviceType, name string) []string

Links returns the apps a service is linked to, sorted.

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

func (s *Server) Property(plugin, appName, property string) (string, bool)

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

Run answers one command. It is the runner Context installs, exported so a test can wrap it.

func (*Server) Scale

func (s *Server) Scale(appName string) map[string]int

Scale returns a copy of an app's process quantities, zeroes included.

func (*Server) SeedApp

func (s *Server) SeedApp(names ...string) *Server

SeedApp creates each named app that does not exist yet.

func (*Server) SeedBuildpacks

func (s *Server) SeedBuildpacks(appName string, urls ...string) *Server

SeedBuildpacks replaces an app's buildpacks, in precedence order, creating the app if needed.

func (*Server) SeedConfig

func (s *Server) SeedConfig(appName string, values map[string]string) *Server

SeedConfig sets config values on an app, creating the app if needed.

func (*Server) SeedDatastore

func (s *Server) SeedDatastore(name, defaultImage string) *Server

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

func (s *Server) SeedDomains(appName string, domains ...string) *Server

SeedDomains replaces an app's domains, creating the app if needed.

func (*Server) SeedGlobalDomains

func (s *Server) SeedGlobalDomains(domains ...string) *Server

SeedGlobalDomains replaces the global domains.

func (*Server) SeedGlobalProperty

func (s *Server) SeedGlobalProperty(plugin, property, value string) *Server

SeedGlobalProperty sets a plugin property globally. An empty value leaves it unset.

func (s *Server) SeedLink(serviceType, name, appName string) *Server

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

func (s *Server) SeedPlugin(name, version string) *Server

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

func (s *Server) SeedProperty(plugin, appName, property, value string) *Server

SeedProperty sets a plugin property on an app, creating the app if needed. An empty value leaves it unset.

func (*Server) SeedScale

func (s *Server) SeedScale(appName string, scale map[string]int) *Server

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

func (s *Server) SeedService(serviceType, name string, info map[string]string) *Server

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

func (s *Server) SeedVersion(version string) *Server

SeedVersion sets the dokku version the Server reports.

func (*Server) ServiceInfo

func (s *Server) ServiceInfo(serviceType, name string) map[string]string

ServiceInfo returns a copy of what `<service>:info` reports for a service, or nil when it does not exist.

func (*Server) Services

func (s *Server) Services(serviceType string) []string

Services returns the names of the services of a datastore type, sorted.

func (*Server) Unknown

func (s *Server) Unknown() []string

Unknown returns the commands the Server was sent that it does not model and no handler answered, each joined by spaces.

Jump to

Keyboard shortcuts

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