test(tvix): Cover scanForReferences in a test

Aded a few test cases covering the scanForReferences function, which had
been accidentally broken in 976a36c (which is now partially-reverted).
As part of this, since the test needed to generate hashes for store
paths, the logic in MakeStorePath to compress a sha256 hash down to 20
bytes and convert it to base32 has been extracted to a member function
on the Hash class.

Fixes: #34
Change-Id: Ie2d914688a80f42d0234d351a7cc0714fd15709e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1698
Tested-by: BuildkiteCI
Reviewed-by: kanepyork <rikingcoding@gmail.com>
This commit is contained in:
Griffin Smith 2020-08-09 00:27:55 -04:00 committed by glittershark
parent dfab786653
commit d1653533a6
6 changed files with 98 additions and 5 deletions

View file

@ -158,6 +158,10 @@ bool Hash::IsValidBase32(absl::string_view s) {
return true;
}
std::string Hash::ToStorePathHash() const {
return compressHash(*this, kStorePathHashSize).to_string(Base32, false);
}
static std::string printHash32(const Hash& hash) {
assert(hash.hashSize);
size_t len = hash.base32Len();

View file

@ -8,6 +8,9 @@
namespace nix {
// Size of the hashes rendered in store paths, in bytes
constexpr unsigned int kStorePathHashSize = 20;
MakeError(BadHash, Error);
// TODO(grfn): Replace this with the hash type enum from the daemon proto so we
@ -90,6 +93,9 @@ struct Hash {
/* Returns whether the passed string contains entirely valid base32
characters. */
static bool IsValidBase32(absl::string_view s);
// Convert this Hash to the format expected in store paths
[[nodiscard]] std::string ToStorePathHash() const;
};
/* Print a hash in base-16 if it's MD5, or base-32 otherwise. */