From 251a8e3c394f30c0975ce73e819134f4a64f8aac Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 23 Nov 2023 19:56:13 +0000 Subject: [PATCH] hash: allow runtime configuration of supported hashes for testing --- fs/hash/hash.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/hash/hash.go b/fs/hash/hash.go index 4540b40cf..23956cee6 100644 --- a/fs/hash/hash.go +++ b/fs/hash/hash.go @@ -55,6 +55,16 @@ func RegisterHash(name, alias string, width int, newFunc func() hash.Hash) Type return hashType } +// SupportOnly makes the hash package only support the types passed +// in. Used for testing. +// +// It returns the previously supported types. +func SupportOnly(new []Type) (old []Type) { + old = supported + supported = new + return old +} + // ErrUnsupported should be returned by filesystem, // if it is requested to deliver an unsupported hash type. var ErrUnsupported = errors.New("hash type not supported")