Documentation ¶
Overview ¶
Package hooktest contains utilities for testing gocharm hooks.
Index ¶
Constants ¶
const UUID = "373b309b-4a86-4f13-88e2-c213d97075b8"
UUID holds an arbitrary environment UUID for testing purposes.
Variables ¶
This section is empty.
Functions ¶
func NewServiceFunc ¶
func NewServiceFunc(r *Runner, notify chan ServiceEvent) func(service.OSServiceParams) service.OSService
NewServiceFunc returns a function that can be used to create new services and can be assigned to service.NewService to mock the OS-level service creator. When the service is started, the given Runner will be used to run it (via hook.Main).
If the notify channel is not nil, it will be used to send events about services created with the function. It should be buffered with a size of at least 2.
Types ¶
type MemState ¶
MemState implements hook.PersistentState in memory. Each element of the map holds the value key stored in the state.
type Runner ¶
type Runner struct { RegisterHooks func(r *hook.Registry) // The following fields hold information that will // be available through the hook context. Relations map[hook.RelationId]map[hook.UnitId]map[string]string RelationIds map[string][]hook.RelationId Config map[string]interface{} PublicAddress string PrivateAddress string // HookStateDir holds the directory in which state // other than hook state will be stored (for instance, // this is used by the service package to store service // logs). If this is empty, RunHook will panic. HookStateDir string // State holds the persistent state. // If it is nil, it will be set to a hooktest.MemState // instance. State hook.PersistentState // RunFunc is called when a hook tool runs. // It may be nil, in which case it will be assumed // that the hook tool runs successfully with no output. RunFunc func(string, ...string) ([]byte, error) Record [][]string // Logger should be set to a logger. The Logf method // will be called when the charm generates log messages. Logger interface { Logf(string, ...interface{}) } // Close records whether the Close method has been called. Closed bool }
Runner is implementation of hook.Runner suitable for use in tests. It calls the given RunFunc function whenever the Run method and records all the calls in the Record field, with the exception of the calls mentioned below.
Any calls to juju-log are logged using Logger, but otherwise ignored. Calls to config-get from the Config field and not invoked through RunFunc. Likewise, calls to unit-get will be satisfied from the PublicAddress and PrivateAddress fields.
func (*Runner) RunCommand ¶
RunCommand runs the given command in the context of the Runner. The cmdName should be a name returned by hook.Context.CommandName.
type ServiceEvent ¶
type ServiceEvent struct { // Kind holds the kind of the service event. Kind ServiceEventKind // Params holds the parameters used to create the service, Params service.OSServiceParams // Error holds an error returned from the service's // command. It is valid only for ServiceEventError // events. Error error }
ServiceEvent represents an event on a service created by the function returned from NewServiceFunc.
type ServiceEventKind ¶
type ServiceEventKind int
ServiceEventKind represents the kind of a ServiceEvent.
const ( // ServiceEventInstall happens when a service is installed. ServiceEventInstall ServiceEventKind // ServiceEventStart happens when a service is started. ServiceEventStart // ServiceEventError happens when a service's command // terminates with an error. ServiceEventError // ServiceEventStop happens when a service is stopped. ServiceEventStop // ServiceEventRemove happens when a service is removed. // The service will always be stopped first. ServiceEventRemove )
func (ServiceEventKind) String ¶
func (i ServiceEventKind) String() string