Documentation ¶
Index ¶
- Constants
- Variables
- func GetLogger() types.Logger
- type CacheAlgorithm
- func (c *CacheAlgorithm) AddObject(o *types.ObjectIndex) error
- func (c *CacheAlgorithm) ChangeConfig(_, _, _ uint64)
- func (c *CacheAlgorithm) ConsumedSize() types.BytesSize
- func (c *CacheAlgorithm) Lookup(o *types.ObjectIndex) bool
- func (c *CacheAlgorithm) PromoteObject(o *types.ObjectIndex)
- func (c *CacheAlgorithm) Remove(os ...*types.ObjectIndex)
- func (c *CacheAlgorithm) SetFakeReplies(index *types.ObjectIndex, replies *CacheAlgorithmRepliers)
- func (c *CacheAlgorithm) ShouldKeep(o *types.ObjectIndex) bool
- func (c *CacheAlgorithm) Stats() types.CacheStats
- type CacheAlgorithmRepliers
- type Logger
- func (b *Logger) Clear()
- func (b *Logger) Debug(args ...interface{})
- func (b *Logger) Debugf(format string, args ...interface{})
- func (b *Logger) Error(args ...interface{})
- func (b *Logger) Errorf(format string, args ...interface{})
- func (b *Logger) Fatal(args ...interface{})
- func (b *Logger) Fatalf(format string, args ...interface{})
- func (b *Logger) Log(args ...interface{})
- func (b *Logger) Logf(format string, args ...interface{})
- func (b *Logger) Logged() []string
- type RequestHandler
- type Storage
- func (s *Storage) ChangeConfig(_ types.Logger)
- func (s *Storage) Discard(id *types.ObjectID) error
- func (s *Storage) DiscardPart(idx *types.ObjectIndex) error
- func (s *Storage) GetAvailableParts(oid *types.ObjectID) ([]*types.ObjectIndex, error)
- func (s *Storage) GetMetadata(id *types.ObjectID) (*types.ObjectMetadata, error)
- func (s *Storage) GetPart(idx *types.ObjectIndex) (io.ReadCloser, error)
- func (s *Storage) Iterate(callback func(*types.ObjectMetadata, ...*types.ObjectIndex) bool) error
- func (s *Storage) PartSize() uint64
- func (s *Storage) SaveMetadata(m *types.ObjectMetadata) error
- func (s *Storage) SavePart(idx *types.ObjectIndex, data io.Reader) error
Constants ¶
const ( FatalPrefix = "Fatal:" ErrorPrefix = "Error:" LogPrefix = "Log:" DebugPrefix = "Debug:" )
Prefixes for the logged messages
const DefaultRequestHandlerResponse = "Hello"
DefaultRequestHandlerResponse is the default response for all requests.
const DefaultRequestHandlerResponseCode = http.StatusOK
DefaultRequestHandlerResponseCode is the default response code for all requests.
const FatalPanicText = "Fatal called"
FatalPanicText is the text of the panic when Fatalf? is called
Variables ¶
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 ¶
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 ¶
Logger writes all the logs and can return them for later examination
func (*Logger) Debug ¶
func (b *Logger) Debug(args ...interface{})
Debug logs a message with fmt.Sprint adding DebugPrefix infront
func (*Logger) Error ¶
func (b *Logger) Error(args ...interface{})
Error logs a message with fmt.Sprint 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 ¶
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
type RequestHandler ¶
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 ¶
NewStorage returns a new mock storage that ready for use.
func (*Storage) ChangeConfig ¶
ChangeConfig does nothing
func (*Storage) DiscardPart ¶
func (s *Storage) DiscardPart(idx *types.ObjectIndex) error
DiscardPart removes the specified part of the object.
func (*Storage) GetAvailableParts ¶
GetAvailableParts returns an io.ReadCloser that will read the specified part of the object.
func (*Storage) GetMetadata ¶
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) SaveMetadata ¶
func (s *Storage) SaveMetadata(m *types.ObjectMetadata) error
SaveMetadata saves the supplied metadata.