mock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mock provides a mock service provider which implements cloud.Provider interface.

Index

Constants

View Source
const (
	// StatusRunning means an instance is still running.
	StatusRunning = "running"
	// StatusTerminated means an instance has been terminated.
	StatusTerminated = "terminated"
	// StatusPending means a task is pending now.
	StatusPending = "pending"
	// StatusWaiting means a task is waiting to be run.
	StatusWaiting = "waiting"
)

Variables

View Source
var (
	// ErrQueueNotExist means a specified queue doesn't exist.
	ErrQueueNotExist = fmt.Errorf("specified queue does not exist")
	// ErrQueueIsNotStopped means a specified queue is not stopped.
	ErrQueueIsNotStopped = fmt.Errorf("specified queue is not stopped")
	// ErrTaskNotExist means a specified task doesn't exist.
	ErrTaskNotExist = fmt.Errorf("specifies task does not exist")
)
View Source
var (
	// ErrServiceFailure is an error used in tests.
	ErrServiceFailure = fmt.Errorf("this service is out of order")
)

Functions

This section is empty.

Types

type InstanceManager added in v0.4.0

type InstanceManager struct {
	// Failure is set ture, all methods return ErrServiceFailure.
	Failure bool
	// Status is a map to maintain instance's status; each key represents an
	// instance name and the associated value represents its status.
	Status map[string]string
	// Script is a map to maintain scripts: each key represents an instance name
	// and the associated value represents a pointer of the script the instance
	// runs on.
	Script map[string]*script.Script
}

InstanceManager is a mock instance manager.

func NewInstanceManager added in v0.4.0

func NewInstanceManager() *InstanceManager

NewInstanceManager creates a new mock instance manager.

func (*InstanceManager) CreateInstance added in v0.4.0

func (m *InstanceManager) CreateInstance(ctx context.Context, s *script.Script) (err error)

CreateInstance creates an instance which has a given name.

func (*InstanceManager) DeleteInstance added in v0.4.0

func (m *InstanceManager) DeleteInstance(ctx context.Context, name string) (err error)

DeleteInstance deletes the given named instance.

func (*InstanceManager) Instances added in v0.4.0

func (m *InstanceManager) Instances(ctx context.Context, handler cloud.InstanceHandler) (err error)

Instances returns a list of running instances

type LogEntry added in v0.4.0

type LogEntry struct {
	// Time is the time the log entry posted.
	Time time.Time
	// Body is the message body of this log entry.
	Body string
	// Stderr to output this entry to stderr instead of stdout.
	Stderr bool
}

LogEntry defines a log entry which has a time and a body.

type LogManager added in v0.4.0

type LogManager struct {
	// Failure is set true, all methods will return ErrServiceFailure.
	Failure bool
	// Logs is a map to maintain log entries. The key of the map is instance names
	// and associated values are log entries for the instance.
	Logs map[string][]LogEntry
	// KeepAlive is true then Get returns nil otherwise io.EOF.
	KeepAlive bool
	// Break defines a break point when Get returns entries before that point.
	// Onece, the break point is used, it will be removed and KeepAlive will be
	// false.
	Break time.Time
	// QueueLogs holds log entries for queues.
	QueueLogs map[string][]LogEntry
}

LogManager is a mock log manager.

func NewLogManager added in v0.4.0

func NewLogManager() *LogManager

NewLogManager creates a new mock log manager.

func (*LogManager) Delete added in v0.4.0

func (m *LogManager) Delete(ctx context.Context, instanceName string) error

Delete instance log.

func (*LogManager) Get added in v0.4.0

func (m *LogManager) Get(ctx context.Context, instanceName string, after time.Time, handler cloud.LogHandler) (err error)

Get instance log.

func (*LogManager) GetQueueLog added in v0.4.0

func (m *LogManager) GetQueueLog(ctx context.Context, queue string, handler cloud.LogHandler) (err error)

GetQueueLog retrievs log entries from a given queue.

func (*LogManager) GetTaskLog added in v0.4.0

func (m *LogManager) GetTaskLog(ctx context.Context, queue, task string, handler cloud.LogHandler) (err error)

GetTaskLog retrieves log entries from a task in a queue.

type Provider

type Provider struct {
	MockInstanceManager *InstanceManager
	MockQueueManager    *QueueManager
	MockStorageManager  *StorageManager
	MockLogManager      *LogManager
	MockResourceManager *ResourceManager
}

Provider is a mock provider for tests.

func NewProvider

func NewProvider() *Provider

NewProvider creates a new mock provider.

func (*Provider) InstanceManager

func (m *Provider) InstanceManager(ctx context.Context) (cloud.InstanceManager, error)

InstanceManager returns an instance manager interface.

func (*Provider) LogManager

func (m *Provider) LogManager(ctx context.Context) (cloud.LogManager, error)

LogManager returns a log manager interface.

func (*Provider) QueueManager

func (m *Provider) QueueManager(ctx context.Context) (cloud.QueueManager, error)

QueueManager returns a queue manager interface.

func (*Provider) ResourceManager

func (m *Provider) ResourceManager(ctx context.Context) (cloud.ResourceManager, error)

ResourceManager returns a mock resrouce manager.

func (*Provider) StorageManager

func (m *Provider) StorageManager(ctx context.Context) (cloud.StorageManager, error)

StorageManager returns a storage manager interface.

type QueueManager added in v0.4.0

type QueueManager struct {
	Failure bool
	Status  map[string][]string
	Script  map[string][]*script.Script
	Worker  map[string]int
}

QueueManager is a mock service implementing cloud.QueueManager.

func NewQueueManager added in v0.4.0

func NewQueueManager() *QueueManager

NewQueueManager creates a new mock queue manager.

func (*QueueManager) CreateWorkers added in v0.4.0

func (m *QueueManager) CreateWorkers(ctx context.Context, queue string, n int, handler cloud.QueueManagerNameHandler) (err error)

CreateWorkers creates worker instances working for a given named queue.

func (*QueueManager) DeleteQueue added in v0.4.0

func (m *QueueManager) DeleteQueue(ctx context.Context, queue string) error

DeleteQueue deletes a given named queue.

func (*QueueManager) DeleteTask added in v0.4.0

func (m *QueueManager) DeleteTask(ctx context.Context, queue, task string) error

DeleteTask deletes a given named task in a given named queue.

func (*QueueManager) Enqueue added in v0.4.0

func (m *QueueManager) Enqueue(ctx context.Context, queue string, task *script.Script) error

Enqueue a new task to a given named queue.

func (*QueueManager) Queues added in v0.4.0

func (m *QueueManager) Queues(ctx context.Context, handler cloud.QueueStatusHandler) (err error)

Queues retrieves existing queue names.

func (*QueueManager) Restart added in v0.4.0

func (m *QueueManager) Restart(ctx context.Context, queue string) error

Restart executing tasks in a given names queue.

func (*QueueManager) Stop added in v0.4.0

func (m *QueueManager) Stop(ctx context.Context, queue string) error

Stop executing tasks in a given named queue.

func (*QueueManager) Tasks added in v0.4.0

func (m *QueueManager) Tasks(ctx context.Context, queue string, handler cloud.QueueManagerTaskHandler) (err error)

Tasks retrieves tasks in a given names queue.

func (*QueueManager) Workers added in v0.4.0

func (m *QueueManager) Workers(ctx context.Context, queue string, handler cloud.QueueManagerNameHandler) (err error)

Workers retrieves worker instance names for a given queue.

type ResourceManager added in v0.4.0

type ResourceManager struct {

	// Available machine types
	AvailableMachineTypes []cloud.MachineType
	// Available regions
	AvailableRegions []cloud.Region
	// Failure if set true, MachineTypes and Regions will return ErrServiceFailure.
	Failure bool
	// contains filtered or unexported fields
}

ResourceManager is a mock service implementing cloud.ResourceManager interface.

func NewResourceManager added in v0.4.0

func NewResourceManager() *ResourceManager

NewResourceManager returns a mock resource manager.

func (*ResourceManager) GetMachineType added in v0.4.0

func (m *ResourceManager) GetMachineType() string

GetMachineType returns a machine type the current project uses by default.

func (*ResourceManager) GetProjectID added in v0.4.0

func (m *ResourceManager) GetProjectID() string

GetProjectID returns an ID of the current project.

func (*ResourceManager) GetRegion added in v0.4.0

func (m *ResourceManager) GetRegion() string

GetRegion returns a region name the current project working on.

func (*ResourceManager) MachineTypes added in v0.4.0

func (m *ResourceManager) MachineTypes(ctx context.Context) ([]cloud.MachineType, error)

MachineTypes returns a set of available machine types.

func (*ResourceManager) Regions added in v0.4.0

func (m *ResourceManager) Regions(ctx context.Context) ([]cloud.Region, error)

Regions returns a set of available regions.

func (*ResourceManager) SetMachineType added in v0.4.0

func (m *ResourceManager) SetMachineType(v string)

SetMachineType sets a machine type as the default one.

func (*ResourceManager) SetProjectID added in v0.4.0

func (m *ResourceManager) SetProjectID(v string)

SetProjectID sets an ID to the current project.

func (*ResourceManager) SetRegion added in v0.4.0

func (m *ResourceManager) SetRegion(v string)

SetRegion sets a region to the current project.

type StorageManager

type StorageManager struct {
	// If true, all method returns an error.
	Failure bool
	// contains filtered or unexported fields
}

StorageManager is a memory based mock storage manager.

func NewStorageManager

func NewStorageManager() *StorageManager

NewStorageManager creates a new mock storage manager.

func (*StorageManager) Delete

func (s *StorageManager) Delete(ctx context.Context, loc *url.URL) error

Delete deletes a file pointed by a given URL.

func (*StorageManager) Download

func (s *StorageManager) Download(ctx context.Context, loc *url.URL, out io.Writer) error

Download writes bytes from the map storage with a given key loc to a given writer.

func (*StorageManager) GetFileInfo

func (s *StorageManager) GetFileInfo(ctx context.Context, loc *url.URL) (*cloud.FileInfo, error)

GetFileInfo returns information of a file pointed by a given URL.

func (*StorageManager) List

func (s *StorageManager) List(ctx context.Context, loc *url.URL, handler cloud.FileInfoHandler) (err error)

List lists up files in this storage and passes each information to a given handler.

func (*StorageManager) Upload

func (s *StorageManager) Upload(ctx context.Context, loc *url.URL, in io.Reader) (err error)

Upload reads bytes from a given stream and stores it in the map storage with a given location as the key.

Jump to

Keyboard shortcuts

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