tests

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareJSON added in v1.23.0

func CompareJSON(t *testing.T, actual, expected []byte)

CompareJSON takes two byte slices, unmarshals them to TestEvent and compares them, failing the test if they don't match

func MakeTempDir

func MakeTempDir(t *testing.T) string

MakeTempDir creates the temp dir and returns the path

Types

type FakeFile added in v1.2.0

type FakeFile struct {
	// contains filtered or unexported fields
}

FakeFile satisfies fdWriter

func NewFakeFile added in v1.2.0

func NewFakeFile() *FakeFile

NewFakeFile creates a FakeFile

func (*FakeFile) Fd added in v1.2.0

func (f *FakeFile) Fd() uintptr

Fd returns the file descriptor

func (*FakeFile) String added in v1.2.0

func (f *FakeFile) String() string

func (*FakeFile) Write added in v1.2.0

func (f *FakeFile) Write(p []byte) (int, error)

type FakeStore added in v0.31.0

type FakeStore struct {
	Hosts map[string]*host.Host
	T     *testing.T
}

FakeStore implements persist.Store from libmachine

func (*FakeStore) Exists added in v0.31.0

func (s *FakeStore) Exists(name string) (bool, error)

Exists determines if the host already exists.

func (*FakeStore) List added in v0.31.0

func (s *FakeStore) List() ([]string, error)

List returns the list of hosts.

func (*FakeStore) Load added in v0.31.0

func (s *FakeStore) Load(name string) (*host.Host, error)

Load loads a host from disk.

func (*FakeStore) Remove added in v0.31.0

func (s *FakeStore) Remove(name string) error

Remove removes a machine from the store

func (*FakeStore) Save added in v0.31.0

func (s *FakeStore) Save(h *host.Host) error

Save persists a machine in the store

type MockAPI

type MockAPI struct {
	FakeStore
	CreateError   bool
	RemoveError   bool
	NotExistError bool
	SaveCalled    bool
	// contains filtered or unexported fields
}

MockAPI is a struct used to mock out libmachine.API

func NewMockAPI

func NewMockAPI(t *testing.T) *MockAPI

NewMockAPI returns a new MockAPI

func (*MockAPI) Close

func (api *MockAPI) Close() error

Close closes the API.

func (*MockAPI) Create

func (api *MockAPI) Create(h *host.Host) error

Create creates the actual host.

func (MockAPI) GetMachinesDir

func (api MockAPI) GetMachinesDir() string

GetMachinesDir returns the directory to store machines in.

func (*MockAPI) List

func (api *MockAPI) List() ([]string, error)

List the existing hosts.

func (*MockAPI) Load

func (api *MockAPI) Load(name string) (*host.Host, error)

Load a created mock

func (*MockAPI) Logf added in v1.3.0

func (api *MockAPI) Logf(format string, args ...interface{})

Logf logs mock interactions

func (*MockAPI) NewHost

func (api *MockAPI) NewHost(drvName string, rawDriver []byte) (*host.Host, error)

NewHost creates a new host.Host instance.

func (*MockAPI) Remove

func (api *MockAPI) Remove(name string) error

Remove a host.

func (*MockAPI) Save

func (api *MockAPI) Save(host *host.Host) error

Save saves a host to disk.

type MockDetector added in v0.4.0

type MockDetector struct {
	Provisioner *MockProvisioner
}

MockDetector can detect MockProvisioner

func (*MockDetector) DetectProvisioner added in v0.4.0

func (m *MockDetector) DetectProvisioner(_ drivers.Driver) (provision.Provisioner, error)

DetectProvisioner detects a provisioner

type MockDriver

type MockDriver struct {
	drivers.BaseDriver
	CurrentState  state.State
	RemoveError   bool
	NotExistError bool
	HostError     bool
	Port          int
	IP            string
	T             *testing.T
}

MockDriver is a struct used to mock out libmachine.Driver

func (*MockDriver) Create

func (d *MockDriver) Create() error

Create creates a MockDriver instance

func (*MockDriver) DriverName added in v1.3.0

func (d *MockDriver) DriverName() string

DriverName returns the name of the driver

func (*MockDriver) GetCreateFlags

func (d *MockDriver) GetCreateFlags() []mcnflag.Flag

GetCreateFlags returns the flags used to create a MockDriver

func (*MockDriver) GetIP

func (d *MockDriver) GetIP() (string, error)

GetIP returns the IP address

func (*MockDriver) GetSSHHostname

func (d *MockDriver) GetSSHHostname() (string, error)

GetSSHHostname returns the hostname for SSH

func (*MockDriver) GetSSHKeyPath

func (d *MockDriver) GetSSHKeyPath() string

GetSSHKeyPath returns the key path for SSH

func (*MockDriver) GetSSHPort

func (d *MockDriver) GetSSHPort() (int, error)

GetSSHPort returns the SSH port

func (*MockDriver) GetState

func (d *MockDriver) GetState() (state.State, error)

GetState returns the state of the driver

func (*MockDriver) GetURL

func (d *MockDriver) GetURL() (string, error)

GetURL returns the URL of the driver

func (*MockDriver) Kill

func (d *MockDriver) Kill() error

Kill kills the machine

func (*MockDriver) Logf added in v1.3.0

func (d *MockDriver) Logf(format string, args ...interface{})

Logf logs mock interactions

func (*MockDriver) Remove

func (d *MockDriver) Remove() error

Remove removes the machine

func (*MockDriver) Restart

func (d *MockDriver) Restart() error

Restart restarts the machine

func (*MockDriver) SetConfigFromFlags

func (d *MockDriver) SetConfigFromFlags(_ drivers.DriverOptions) error

SetConfigFromFlags sets the machine config

func (*MockDriver) Start

func (d *MockDriver) Start() error

Start starts the machine

func (*MockDriver) Stop

func (d *MockDriver) Stop() error

Stop stops the machine

type MockHost added in v0.4.0

type MockHost struct {
	CommandOutput map[string]string
	Error         string
	Commands      map[string]int
	Driver        drivers.Driver
}

MockHost used for testing. When commands are run, the output from CommandOutput is used, if present. Then the output from Error is used, if present. Finally, "", nil is returned.

func NewMockHost added in v0.4.0

func NewMockHost() *MockHost

NewMockHost creates a new MockHost

func (MockHost) RunSSHCommand added in v0.4.0

func (m MockHost) RunSSHCommand(cmd string) (string, error)

RunSSHCommand runs a SSH command, returning output

type MockProvisioner added in v0.4.0

type MockProvisioner struct {
	Provisioned bool
}

MockProvisioner defines distribution specific actions

func (*MockProvisioner) AttemptIPContact added in v0.4.0

func (provisioner *MockProvisioner) AttemptIPContact(_ int)

AttemptIPContact attempts to contact an IP and port

func (*MockProvisioner) CompatibleWithHost added in v0.4.0

func (provisioner *MockProvisioner) CompatibleWithHost() bool

CompatibleWithHost checks if provisioner is compatible with host

func (*MockProvisioner) GenerateDockerOptions added in v0.4.0

func (provisioner *MockProvisioner) GenerateDockerOptions(_ int) (*provision.DockerOptions, error)

GenerateDockerOptions generates Docker options

func (*MockProvisioner) GetAuthOptions added in v0.4.0

func (provisioner *MockProvisioner) GetAuthOptions() auth.Options

GetAuthOptions returns a the auth.Options

func (*MockProvisioner) GetDockerOptionsDir added in v0.4.0

func (provisioner *MockProvisioner) GetDockerOptionsDir() string

GetDockerOptionsDir gets Docker options dir

func (*MockProvisioner) GetDriver added in v0.4.0

func (provisioner *MockProvisioner) GetDriver() drivers.Driver

GetDriver gets the driver

func (*MockProvisioner) GetOsReleaseInfo added in v0.4.0

func (provisioner *MockProvisioner) GetOsReleaseInfo() (*provision.OsRelease, error)

GetOsReleaseInfo gets the os-release info

func (*MockProvisioner) GetSwarmOptions added in v0.11.0

func (provisioner *MockProvisioner) GetSwarmOptions() swarm.Options

GetSwarmOptions gets the swarm.Options

func (*MockProvisioner) Hostname added in v0.4.0

func (provisioner *MockProvisioner) Hostname() (string, error)

Hostname returns the hostname

func (*MockProvisioner) Package added in v0.4.0

func (provisioner *MockProvisioner) Package(_ string, _ pkgaction.PackageAction) error

Package performs an action for a package

func (*MockProvisioner) Provision added in v0.4.0

func (provisioner *MockProvisioner) Provision(_ swarm.Options, _ auth.Options, _ engine.Options) error

Provision provisions the machine

func (*MockProvisioner) SSHCommand added in v0.4.0

func (provisioner *MockProvisioner) SSHCommand(_ string) (string, error)

SSHCommand runs a SSH command

func (*MockProvisioner) Service added in v0.4.0

func (provisioner *MockProvisioner) Service(_ string, _ serviceaction.ServiceAction) error

Service performs an action for a service

func (*MockProvisioner) SetHostname added in v0.4.0

func (provisioner *MockProvisioner) SetHostname(_ string) error

SetHostname sets the hostname

func (*MockProvisioner) SetOsReleaseInfo added in v0.4.0

func (provisioner *MockProvisioner) SetOsReleaseInfo(_ *provision.OsRelease)

SetOsReleaseInfo sets the os-release info

func (*MockProvisioner) String added in v0.4.0

func (provisioner *MockProvisioner) String() string

type SSHServer

type SSHServer struct {
	Config *ssh.ServerConfig
	// Commands stores the raw commands executed against the server.
	Commands  map[string]int
	Connected bool
	Transfers *bytes.Buffer
	// contains filtered or unexported fields
}

SSHServer provides a mock SSH Server for testing. Commands are stored, not executed.

func NewSSHServer

func NewSSHServer(t *testing.T) (*SSHServer, error)

NewSSHServer returns a NewSSHServer instance, ready for use.

func (*SSHServer) GetCommandToOutput added in v0.17.0

func (s *SSHServer) GetCommandToOutput(cmd string) (string, error)

GetCommandToOutput gets command to output

func (*SSHServer) IsSessionRequested added in v0.17.0

func (s *SSHServer) IsSessionRequested() bool

IsSessionRequested gcode ets session requested

func (*SSHServer) SetCommandToOutput added in v0.17.0

func (s *SSHServer) SetCommandToOutput(cmdToOutput map[string]string)

SetCommandToOutput sets command to output

func (*SSHServer) SetSessionRequested added in v0.17.0

func (s *SSHServer) SetSessionRequested(b bool)

SetSessionRequested sets session requested

func (*SSHServer) Start

func (s *SSHServer) Start() (int, error)

Start the mock SSH Server

func (*SSHServer) Stop added in v1.3.0

func (s *SSHServer) Stop()

Stop the mock SSH server

type TestEvent added in v1.23.0

type TestEvent struct {
	Data            map[string]string `json:"data"`
	Datacontenttype string            `json:"datacontenttype"`
	ID              string            `json:"id"`
	Source          string            `json:"source"`
	Specversion     string            `json:"specversion"`
	Eventtype       string            `json:"type"`
}

TestEvent simulates a CloudEvent for our JSON output

Jump to

Keyboard shortcuts

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