fstest: add ability for mock objects and filesystems to have hashes
This commit is contained in:
parent
c820576329
commit
25662b9e05
2 changed files with 21 additions and 1 deletions
|
@ -18,6 +18,7 @@ type Fs struct {
|
|||
root string // The root directory (OS path)
|
||||
features *fs.Features // optional features
|
||||
rootDir fs.DirEntries // directory listing of root
|
||||
hashes hash.Set // which hashes we support
|
||||
}
|
||||
|
||||
// ErrNotImplemented is returned by unimplemented methods
|
||||
|
@ -66,7 +67,12 @@ func (f *Fs) Precision() time.Duration {
|
|||
|
||||
// Hashes returns the supported hash types of the filesystem
|
||||
func (f *Fs) Hashes() hash.Set {
|
||||
return hash.NewHashSet()
|
||||
return f.hashes
|
||||
}
|
||||
|
||||
// SetHashes sets the hashes that this supports
|
||||
func (f *Fs) SetHashes(hashes hash.Set) {
|
||||
f.hashes = hashes
|
||||
}
|
||||
|
||||
// Features returns the optional features of this Fs
|
||||
|
|
|
@ -178,6 +178,20 @@ func (o *ContentMockObject) Size() int64 {
|
|||
return int64(len(o.content))
|
||||
}
|
||||
|
||||
// Hash returns the selected checksum of the file
|
||||
// If no checksum is available it returns ""
|
||||
func (o *ContentMockObject) Hash(ctx context.Context, t hash.Type) (string, error) {
|
||||
hasher, err := hash.NewMultiHasherTypes(hash.NewHashSet(t))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, err = hasher.Write(o.content)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hasher.Sums()[t], nil
|
||||
}
|
||||
|
||||
type readCloser struct{ io.Reader }
|
||||
|
||||
func (r *readCloser) Close() error { return nil }
|
||||
|
|
Loading…
Reference in a new issue