Documentation
¶
Index ¶
- type Command
- type MockCommandReturn
- type MockSystem
- func (r *MockSystem) MkHomeSubdirectory(subdirectory string) error
- func (r *MockSystem) MockCommandReturn(command string, b []byte, err error)
- func (r *MockSystem) MockFile(filePath string, contents []byte)
- func (r *MockSystem) MockSnapChannels(snap string, channels []string)
- func (r *MockSystem) MockSnapStoreLookup(name, channel string, classic, installed bool) *Snap
- func (r *MockSystem) ReadFile(filePath string) ([]byte, error)
- func (r *MockSystem) ReadHomeDirFile(filePath string) ([]byte, error)
- func (r *MockSystem) RemoveAllHome(filePath string) error
- func (r *MockSystem) Run(c *Command) ([]byte, error)
- func (r *MockSystem) RunExclusive(c *Command) ([]byte, error)
- func (r *MockSystem) RunMany(commands ...*Command) error
- func (r *MockSystem) RunWithRetries(c *Command, maxDuration time.Duration) ([]byte, error)
- func (r *MockSystem) SnapChannels(snap string) ([]string, error)
- func (r *MockSystem) SnapInfo(snap string, channel string) (*SnapInfo, error)
- func (r *MockSystem) User() *user.User
- func (r *MockSystem) WriteHomeDirFile(filepath string, contents []byte) error
- type Snap
- type SnapInfo
- type System
- func (s *System) MkHomeSubdirectory(subdirectory string) error
- func (s *System) ReadFile(filePath string) ([]byte, error)
- func (s *System) ReadHomeDirFile(filePath string) ([]byte, error)
- func (s *System) RemoveAllHome(filePath string) error
- func (s *System) Run(c *Command) ([]byte, error)
- func (s *System) RunExclusive(c *Command) ([]byte, error)
- func (s *System) RunMany(commands ...*Command) error
- func (s *System) RunWithRetries(c *Command, maxDuration time.Duration) ([]byte, error)
- func (s *System) SnapChannels(snap string) ([]string, error)
- func (s *System) SnapInfo(snap string, channel string) (*SnapInfo, error)
- func (s *System) User() *user.User
- func (s *System) WriteHomeDirFile(filePath string, contents []byte) error
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
Command represents a given command to be executed by Concierge, along with the user and group that should be assumed if required.
func NewCommand ¶
NewCommand constructs a command to be run as the current user/group.
func NewCommandAs ¶
NewCommandAs constructs a command to be run as the specified user/group.
func (*Command) CommandString ¶
CommandString puts together a command to be executed in a shell, including the `sudo` command and its arguments where appropriate.
type MockCommandReturn ¶
MockCommandReturn contains mocked Output and Error from a given command.
type MockSystem ¶
type MockSystem struct { ExecutedCommands []string CreatedFiles map[string]string CreatedDirectories []string Deleted []string // contains filtered or unexported fields }
MockSystem represents a struct that can emulate running commands.
func (*MockSystem) MkHomeSubdirectory ¶
func (r *MockSystem) MkHomeSubdirectory(subdirectory string) error
MkHomeSubdirectory takes a relative folder path and creates it recursively in the real user's home directory.
func (*MockSystem) MockCommandReturn ¶
func (r *MockSystem) MockCommandReturn(command string, b []byte, err error)
MockCommandReturn sets a static return value representing command combined output, and a desired error return for the specified command.
func (*MockSystem) MockFile ¶
func (r *MockSystem) MockFile(filePath string, contents []byte)
MockFile sets a faked expected file contents for a given file.
func (*MockSystem) MockSnapChannels ¶ added in v0.10.0
func (r *MockSystem) MockSnapChannels(snap string, channels []string)
MockSnapChannels mocks the set of available channels for a snap in the store.
func (*MockSystem) MockSnapStoreLookup ¶
func (r *MockSystem) MockSnapStoreLookup(name, channel string, classic, installed bool) *Snap
MockSnapStoreLookup gets a new test snap and adds a mock snap into the mock test
func (*MockSystem) ReadFile ¶
func (r *MockSystem) ReadFile(filePath string) ([]byte, error)
ReadFile takes a path and reads the content from the specified file.
func (*MockSystem) ReadHomeDirFile ¶
func (r *MockSystem) ReadHomeDirFile(filePath string) ([]byte, error)
ReadHomeDirFile takes a path relative to the real user's home dir, and reads the content from the file
func (*MockSystem) RemoveAllHome ¶
func (r *MockSystem) RemoveAllHome(filePath string) error
RemoveAllHome recursively removes a file path from the user's home directory.
func (*MockSystem) Run ¶
func (r *MockSystem) Run(c *Command) ([]byte, error)
Run executes the command, returning the stdout/stderr where appropriate.
func (*MockSystem) RunExclusive ¶
func (r *MockSystem) RunExclusive(c *Command) ([]byte, error)
RunExclusive is a wrapper around Run that uses a mutex to ensure that only one of that particular command can be run at a time.
func (*MockSystem) RunMany ¶
func (r *MockSystem) RunMany(commands ...*Command) error
RunMany takes a variadic number of Command's, and runs them in a loop, returning and error if any command fails.
func (*MockSystem) RunWithRetries ¶
RunWithRetries executes the command, retrying utilising an exponential backoff pattern, which starts at 1 second. Retries will be attempted up to the specified maximum duration.
func (*MockSystem) SnapChannels ¶ added in v0.10.0
func (r *MockSystem) SnapChannels(snap string) ([]string, error)
SnapChannels returns the list of channels available for a given snap.
func (*MockSystem) SnapInfo ¶
func (r *MockSystem) SnapInfo(snap string, channel string) (*SnapInfo, error)
SnapInfo returns information about a given snap, looking up details in the snap store using the snapd client API where necessary.
func (*MockSystem) User ¶
func (r *MockSystem) User() *user.User
User returns the user the system executes commands on behalf of.
func (*MockSystem) WriteHomeDirFile ¶
func (r *MockSystem) WriteHomeDirFile(filepath string, contents []byte) error
WriteHomeDirFile takes a path relative to the real user's home dir, and writes the contents specified to it.
type Snap ¶
Snap represents a given snap on a given channel.
func NewSnapFromString ¶
NewSnapFromString returns a constructed snap instance, where the snap is specified in shorthand form, i.e. `charmcraft/latest/edge`.
type System ¶
type System struct {
// contains filtered or unexported fields
}
System represents a struct that can run commands.
func (*System) MkHomeSubdirectory ¶
MkHomeSubdirectory takes a relative folder path and creates it recursively in the real user's home directory.
func (*System) ReadHomeDirFile ¶
ReadHomeDirFile takes a path relative to the real user's home dir, and reads the content from the file
func (*System) RemoveAllHome ¶
RemoveAllHome recursively removes a file path from the user's home directory.
func (*System) RunExclusive ¶
RunExclusive is a wrapper around Run that uses a mutex to ensure that only one of that particular command can be run at a time.
func (*System) RunMany ¶
RunMany takes a variadic number of Command's, and runs them in a loop, returning and error if any command fails.
func (*System) RunWithRetries ¶
RunWithRetries executes the command, retrying utilising an exponential backoff pattern, which starts at 1 second. Retries will be attempted up to the specified maximum duration.
func (*System) SnapChannels ¶ added in v0.10.0
SnapChannels returns the list of channels available for a given snap.
func (*System) SnapInfo ¶
SnapInfo returns information about a given snap, looking up details in the snap store using the snapd client API where necessary.
type Worker ¶
type Worker interface { // User returns the 'real user' the system executes command as. This may be different from // the current user since the command is often executed with `sudo`. User() *user.User // Run takes a single command and runs it, returning the combined output and an error value. Run(c *Command) ([]byte, error) // RunMany takes multiple commands and runs them in sequence, returning an error on the // first error encountered. RunMany(commands ...*Command) error // RunExclusive is a wrapper around Run that uses a mutex to ensure that only one of that // particular command can be run at a time. RunExclusive(c *Command) ([]byte, error) // RunWithRetries executes the command, retrying utilising an exponential backoff pattern, // which starts at 1 second. Retries will be attempted up to the specified maximum duration. RunWithRetries(c *Command, maxDuration time.Duration) ([]byte, error) // WriteHomeDirFile takes a path relative to the real user's home dir, and writes the contents // specified to it. WriteHomeDirFile(filepath string, contents []byte) error // MkHomeSubdirectory takes a relative folder path and creates it recursively in the real // user's home directory. MkHomeSubdirectory(subdirectory string) error // RemoveAllHome recursively removes a file path from the user's home directory. RemoveAllHome(filePath string) error // ReadHomeDirFile reads a file from the user's home directory. ReadHomeDirFile(filepath string) ([]byte, error) // ReadFile reads a file with an arbitrary path from the system. ReadFile(filePath string) ([]byte, error) // SnapInfo returns information about a given snap, looking up details in the snap // store using the snapd client API where necessary. SnapInfo(snap string, channel string) (*SnapInfo, error) // SnapChannels returns the list of channels available for a given snap. SnapChannels(snap string) ([]string, error) }
Worker is an interface for a struct that can run commands on the underlying system.