mock

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache implements sts.FileCache

func NewCache

func NewCache() *Cache

NewCache initializes the cache

func (*Cache) Add

func (c *Cache) Add(file sts.Hashed)

Add adds a hashed file to the in-memory cache

func (*Cache) Done

func (c *Cache) Done(key string, whileLocked func(sts.Cached))

Done marks the file by the given key as done

func (*Cache) Get

func (c *Cache) Get(key string) sts.Cached

Get returns the stored file with the specified key

func (*Cache) Iterate

func (c *Cache) Iterate(f func(sts.Cached) bool)

Iterate iterates over the cache and calls provided callback on each file

func (*Cache) Persist

func (c *Cache) Persist() (err error)

Persist writes the in-memory cache to disk

func (*Cache) Remove

func (c *Cache) Remove(key string)

Remove removes the file by the specified key from the in-memory cache

func (*Cache) Reset

func (c *Cache) Reset(key string)

Reset marks a file to be sent again

type File

type File struct {
	Name     string
	Renamed  string
	Path     string
	Size     int64
	Time     time.Time
	Meta     []byte
	Hash     string
	SendTime int64
	Done     bool
	// contains filtered or unexported fields
}

File is meant to implement as many of the file-typed interfaces as possible

func (*File) GetHash

func (f *File) GetHash() string

GetHash gets the file signature

func (*File) GetMeta

func (f *File) GetMeta() []byte

GetMeta gets any additional metadata needed by the store implementation

func (*File) GetName

func (f *File) GetName() string

GetName gets the name part of the path

func (*File) GetPath

func (f *File) GetPath() string

GetPath gets the path

func (*File) GetRenamed

func (f *File) GetRenamed() string

GetRenamed gets the new name, if applicable (empty otherwise)

func (*File) GetSize

func (f *File) GetSize() int64

GetSize gets the file size

func (*File) GetTime

func (f *File) GetTime() time.Time

GetTime gets the file mod time

func (*File) IsDone

func (f *File) IsDone() bool

IsDone is obvious

func (*File) TimeMs

func (f *File) TimeMs() int64

TimeMs returns the time (in milliseconds) a file took to be sent

type Logger

type Logger struct {
	DebugMode bool
	// contains filtered or unexported fields
}

Logger mocks logging by just printing to stdout/stderr

func (*Logger) Debug

func (log *Logger) Debug(params ...interface{})

Debug logs debug messages

func (*Logger) Error

func (log *Logger) Error(params ...interface{})

Error logs ...errors

func (*Logger) Info

func (log *Logger) Info(params ...interface{})

Info logs general information

func (*Logger) Recent

func (log *Logger) Recent(n int) (msgs []string)

Recent returns recent messages (at least, it's supposed to)

type MissingError

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

MissingError is a simple wrapper around the standard error

type Readable

type Readable struct {
	*bytes.Reader
}

Readable mocks sts.Readable using a generic bytes reader

func (Readable) Close

func (Readable) Close() error

Close is a noop just so we can satisfy the interface

type RecoveredFile

type RecoveredFile struct {
	sts.Hashed
	Prev string
}

RecoveredFile is meant to be a recovered and fully allocated file

func (*RecoveredFile) Allocate

func (f *RecoveredFile) Allocate(int64) (int64, int64)

Allocate does nothing

func (*RecoveredFile) GetPrev

func (f *RecoveredFile) GetPrev() string

GetPrev returns any configured previous file

func (*RecoveredFile) IsAllocated

func (f *RecoveredFile) IsAllocated() bool

IsAllocated is always true

type Store

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

Store mocks sts.FileSource

func NewStore

func NewStore(n, size int) *Store

NewStore creates a new Store with n files gradually ranging to size

func (*Store) GetOpener

func (s *Store) GetOpener() sts.Open

GetOpener implements sts.FileSource.GetOpener()

func (*Store) IsNotExist

func (s *Store) IsNotExist(err error) bool

IsNotExist returns whether or not the provided error indicates a file is missing

func (*Store) Remove

func (s *Store) Remove(file sts.File) error

Remove implements sts.FileSource.Remove()

func (*Store) Scan

func (s *Store) Scan(allow func(sts.File) bool) ([]sts.File, time.Time, error)

Scan implements sts.FileSource.Scan()

func (*Store) Sync

func (s *Store) Sync(file sts.File) (sts.File, error)

Sync implements sts.FileSource.Sync()

Jump to

Keyboard shortcuts

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