mock

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: May 27, 2016 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FatalPrefix = "Fatal:"
	ErrorPrefix = "Error:"
	LogPrefix   = "Log:"
	DebugPrefix = "Debug:"
)

Prefixes for the logged messages

View Source
const DefaultRequestHandlerResponse = "Hello"

DefaultRequestHandlerResponse is the default response for all requests.

View Source
const DefaultRequestHandlerResponseCode = http.StatusOK

DefaultRequestHandlerResponseCode is the default response code for all requests.

View Source
const FatalPanicText = "Fatal called"

FatalPanicText is the text of the panic when Fatalf? is called

Variables

View Source
var DefaultCacheAlgorithmRepliers = CacheAlgorithmRepliers{
	Lookup:        func(*types.ObjectIndex) bool { return false },
	ShouldKeep:    func(*types.ObjectIndex) bool { return false },
	AddObject:     func(*types.ObjectIndex) error { return nil },
	PromoteObject: func(*types.ObjectIndex) {},
	Remove:        func(...*types.ObjectIndex) {},
}

DefaultCacheAlgorithmRepliers always return false and nil

Functions

func GetLogger added in v0.1.14

func GetLogger() types.Logger

GetLogger is the same as NewLogger but returns types.Logger instead of *Logger

Types

type CacheAlgorithm

type CacheAlgorithm struct {
	types.SyncLogger
	Defaults CacheAlgorithmRepliers
	Mapping  map[types.ObjectIndex]*CacheAlgorithmRepliers
}

CacheAlgorithm is used in different tests as a cache algorithm substitute

func NewCacheAlgorithm

func NewCacheAlgorithm(defaults *CacheAlgorithmRepliers) *CacheAlgorithm

NewCacheAlgorithm creates and returns a new mock cache algorithm. The default replies can be specified by the `defaults` argument.

func (*CacheAlgorithm) AddObject

func (c *CacheAlgorithm) AddObject(o *types.ObjectIndex) error

AddObject returns the specified (if present for this index) or default error

func (*CacheAlgorithm) ChangeConfig

func (c *CacheAlgorithm) ChangeConfig(_, _, _ uint64)

ChangeConfig does nothing

func (*CacheAlgorithm) ConsumedSize

func (c *CacheAlgorithm) ConsumedSize() types.BytesSize

ConsumedSize always returns 0

func (*CacheAlgorithm) Lookup

func (c *CacheAlgorithm) Lookup(o *types.ObjectIndex) bool

Lookup returns the specified (if present for this index) or default value

func (*CacheAlgorithm) PromoteObject

func (c *CacheAlgorithm) PromoteObject(o *types.ObjectIndex)

PromoteObject calls the specified (if present for this index) or default callback

func (*CacheAlgorithm) Remove

func (c *CacheAlgorithm) Remove(os ...*types.ObjectIndex)

Remove removes the cpecified objects from the cache. Currently only the default MockRepliers are being used to implement the call

func (*CacheAlgorithm) SetFakeReplies

func (c *CacheAlgorithm) SetFakeReplies(index *types.ObjectIndex, replies *CacheAlgorithmRepliers)

SetFakeReplies is used to customize the replies for certain indexes

func (*CacheAlgorithm) ShouldKeep

func (c *CacheAlgorithm) ShouldKeep(o *types.ObjectIndex) bool

ShouldKeep returns the specified (if present for this index) or default value

func (*CacheAlgorithm) Stats

func (c *CacheAlgorithm) Stats() types.CacheStats

Stats always returns nil

type CacheAlgorithmRepliers

type CacheAlgorithmRepliers struct {
	Lookup        func(*types.ObjectIndex) bool
	ShouldKeep    func(*types.ObjectIndex) bool
	AddObject     func(*types.ObjectIndex) error
	Remove        func(...*types.ObjectIndex)
	PromoteObject func(*types.ObjectIndex)
}

CacheAlgorithmRepliers are used for setting fake reply for a particular index.

type Logger

type Logger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Logger writes all the logs and can return them for later examination

func NewLogger

func NewLogger() *Logger

NewLogger returns a new Buffers logger.

func (*Logger) Clear

func (b *Logger) Clear()

Clear clears the logged messages

func (*Logger) Debug

func (b *Logger) Debug(args ...interface{})

Debug logs a message with fmt.Sprint adding DebugPrefix infront

func (*Logger) Debugf

func (b *Logger) Debugf(format string, args ...interface{})

Debugf logs a message with fmt.Sprintf adding DebugPrefix infront

func (*Logger) Error

func (b *Logger) Error(args ...interface{})

Error logs a message with fmt.Sprint adding ErrorPrefix infront

func (*Logger) Errorf

func (b *Logger) Errorf(format string, args ...interface{})

Errorf logs a message with fmt.Sprintf adding ErrorPrefix infront

func (*Logger) Fatal

func (b *Logger) Fatal(args ...interface{})

Fatal logs a message with fmt.Sprint adding FatalPrefix infront and then panics

func (*Logger) Fatalf

func (b *Logger) Fatalf(format string, args ...interface{})

Fatalf logs a message with fmt.Sprintf adding FatalPrefix infront and then panics

func (*Logger) Log

func (b *Logger) Log(args ...interface{})

Log logs a message with fmt.Sprint with LogPrefix infront

func (*Logger) Logf

func (b *Logger) Logf(format string, args ...interface{})

Logf logs a message with fmt.Sprintf with LogPrefix infront

func (*Logger) Logged

func (b *Logger) Logged() []string

Logged returns a slice of strings that is everything that has been logged since the creation or the last call to Clear.

type RequestHandler

type RequestHandler struct {
	*http.ServeMux
}

RequestHandler is used to set custom responses for testing handler-related things.

func NewRequestHandler

func NewRequestHandler(defaultHandler http.HandlerFunc) *RequestHandler

NewRequestHandler creates and returns a new http.ServeMux instance that serves as a mock upstream. The default handler can be specified. If nil, a simple handler that always returns 200 and "Hello" is used.

func (*RequestHandler) RequestHandle

func (m *RequestHandler) RequestHandle(_ context.Context, w http.ResponseWriter, r *http.Request)

RequestHandle implements the interface

type Storage

type Storage struct {
	types.SyncLogger

	Objects map[types.ObjectIDHash]*types.ObjectMetadata
	Parts   map[types.ObjectIDHash]map[uint32][]byte
	// contains filtered or unexported fields
}

Storage implements the storage interface and is used for testing

func NewStorage

func NewStorage(partSize uint64) *Storage

NewStorage returns a new mock storage that ready for use.

func (*Storage) ChangeConfig

func (s *Storage) ChangeConfig(_ types.Logger)

ChangeConfig does nothing

func (*Storage) Discard

func (s *Storage) Discard(id *types.ObjectID) error

Discard removes the object and its metadata.

func (*Storage) DiscardPart

func (s *Storage) DiscardPart(idx *types.ObjectIndex) error

DiscardPart removes the specified part of the object.

func (*Storage) GetAvailableParts

func (s *Storage) GetAvailableParts(oid *types.ObjectID) ([]*types.ObjectIndex, error)

GetAvailableParts returns an io.ReadCloser that will read the specified part of the object.

func (*Storage) GetMetadata

func (s *Storage) GetMetadata(id *types.ObjectID) (*types.ObjectMetadata, error)

GetMetadata returns the metadata for this object, if present.

func (*Storage) GetPart

func (s *Storage) GetPart(idx *types.ObjectIndex) (io.ReadCloser, error)

GetPart returns an io.ReadCloser that will read the specified part of the object.

func (*Storage) Iterate

func (s *Storage) Iterate(callback func(*types.ObjectMetadata, ...*types.ObjectIndex) bool) error

Iterate iterates over all the objects and passes them to the supplied callback function. If the callback function returns false, the iteration stops.

func (*Storage) PartSize

func (s *Storage) PartSize() uint64

PartSize the maximum part size for the disk storage.

func (*Storage) SaveMetadata

func (s *Storage) SaveMetadata(m *types.ObjectMetadata) error

SaveMetadata saves the supplied metadata.

func (*Storage) SavePart

func (s *Storage) SavePart(idx *types.ObjectIndex, data io.Reader) error

SavePart saves the contents of the supplied object part.

Jump to

Keyboard shortcuts

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