mock

package
v0.0.0-...-3122893 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2015 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TestUser contains account name for log into mock server
	TestUser = "test@example.com"
	// TestPassword contains password for log into mock server
	TestPassword = "test"
)

Variables

View Source
var Drives = &DriveLibrary{
	m: make(map[string]*data.Drive),
	p: "/api/2.0/drives",
}

Drives defines user account drives

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound - drive not found in library error

View Source
var Jobs = &JobLibrary{
	m: make(map[string]*data.Job),
	p: "/api/2.0/jobs",
}

Jobs defines library of all jobs in the mock

View Source
var LibDrives = &DriveLibrary{
	m: make(map[string]*data.Drive),
	p: "/api/2.0/libdrives",
}

LibDrives defines public drives

Functions

func AddServer

func AddServer(s *data.Server) error

AddServer adds server instance record under the mock

func AddServers

func AddServers(ss []data.Server) []string

AddServers adds server instance records under the mock

func Endpoint

func Endpoint(section string) string

Endpoint of mock server, represented as string in form 'https://host:port/api/{version}/{section}'. Panic if server is not started.

func GenerateUUID

func GenerateUUID() (string, error)

GenerateUUID generated new UUID for server

func Get

func Get(section string) (*https.Response, error)

Get performs Get request to the given section of mock server with default authentication

func GetAuth

func GetAuth(section, username, password string) (*https.Response, error)

GetAuth performs Get request to the given section of mock server with authentication

func GetID

func GetID(h http.Header) (int, error)

GetID returns journal ID from HTTP header

func GetIDFromRequest

func GetIDFromRequest(r *http.Request) int

GetIDFromRequest returns journal ID from HTTP request

func GetIDFromResponse

func GetIDFromResponse(r *https.Response) int

GetIDFromResponse returns journal ID from HTTP response

func InitDrive

func InitDrive(d *data.Drive) (*data.Drive, error)

InitDrive initializes drive

func InitJob

func InitJob(j *data.Job) (*data.Job, error)

InitJob initializes the job

func IsStarted

func IsStarted() bool

IsStarted checks the mock server is running

func Log

func Log(t *testing.T, jj []JournalEntry)

Log journal entry to testing log

func LogDetail

func LogDetail(t *testing.T, j JournalEntry)

LogDetail writes detailed information about journal entry to testing log

func LogResponse

func LogResponse(t *testing.T, r *https.Response)

LogResponse log journal entries associated with response to testing log

func LogURL

func LogURL(t *testing.T, j JournalEntry)

LogURL writes URL from journal entry to testing log

func PutJournal

func PutJournal(id int, name string, r *http.Request, rr *httptest.ResponseRecorder)

PutJournal adds record to specified journal

func RemoveServer

func RemoveServer(uuid string) bool

RemoveServer removes server instance record from the mock

func Reset

func Reset()

Reset mock server

func ResetDrives

func ResetDrives()

ResetDrives clean-up all drive libraries

func ResetServers

func ResetServers()

ResetServers removes all server instance records from the mock

func SetID

func SetID(h http.Header, id int)

SetID adds specified journal ID to HTTP header

func SetServerStatus

func SetServerStatus(uuid, status string)

SetServerStatus changes status of server instance in the mock

func Start

func Start()

Start mock server for testing CloudSigma endpoint communication. If server is already started, this function does nothing.

func Stop

func Stop()

Stop mock server. Panic if server is not started.

Types

type DriveLibrary

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

DriveLibrary defines type for mock drive library

func (*DriveLibrary) Add

func (d *DriveLibrary) Add(drv *data.Drive) error

Add drive to the library

func (*DriveLibrary) AddDrives

func (d *DriveLibrary) AddDrives(dd []data.Drive) []string

AddDrives adds drive collection to the library

func (*DriveLibrary) Clone

func (d *DriveLibrary) Clone(uuid string, params map[string]interface{}) (string, error)

Clone drive in the library

func (*DriveLibrary) Remove

func (d *DriveLibrary) Remove(uuid string) bool

Remove drive from the library

func (*DriveLibrary) Reset

func (d *DriveLibrary) Reset()

Reset drive library

func (*DriveLibrary) Resize

func (d *DriveLibrary) Resize(uuid string, size uint64) error

Resize drive in the library

func (*DriveLibrary) SetStatus

func (d *DriveLibrary) SetStatus(uuid, status string)

SetStatus sets drive status in the library

type JobLibrary

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

JobLibrary type to store all jobs in the mock

func (*JobLibrary) Add

func (j *JobLibrary) Add(job *data.Job) error

Add job to the library

func (*JobLibrary) AddJobs

func (j *JobLibrary) AddJobs(jj []data.Job) []string

AddJobs adds job collection to the libraryh

func (*JobLibrary) Remove

func (j *JobLibrary) Remove(uuid string) bool

Remove job from the library

func (*JobLibrary) Reset

func (j *JobLibrary) Reset()

Reset the library

func (*JobLibrary) SetState

func (j *JobLibrary) SetState(uuid, state string)

SetState for the job in the library

type JournalEntry

type JournalEntry struct {
	Name     string
	Request  *http.Request
	Response *httptest.ResponseRecorder
}

JournalEntry contains single journal record

func GetJournal

func GetJournal(id int) []JournalEntry

GetJournal retrivies record from specified journal

Jump to

Keyboard shortcuts

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