chore(3p/nix/hash): add decoding tests

Change-Id: Ifbeaf1822fa920f929482510ee79a5b24d7976ae
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1485
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Kane York 2020-07-27 16:54:19 -07:00 committed by kanepyork
parent d4c9a8afda
commit ec349328e0

View file

@ -21,4 +21,23 @@ TEST(HASH_TEST, SHA256) {
"sha256:LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=");
}
TEST(HashTest, SHA256Decode) {
auto hash = hashString(HashType::htSHA256, "foo");
std::unique_ptr<Hash> base16 = std::make_unique<Hash>(
"sha256:"
"2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae",
HashType::htSHA256);
std::unique_ptr<Hash> base32 = std::make_unique<Hash>(
"sha256:1bp7cri8hplaz6hbz0v4f0nl44rl84q1sg25kgwqzipzd1mv89ic",
HashType::htSHA256);
std::unique_ptr<Hash> base64 = std::make_unique<Hash>(
"sha256:LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=",
HashType::htSHA256);
ASSERT_EQ(hash, *base16);
ASSERT_EQ(hash, *base32);
ASSERT_EQ(hash, *base64);
}
} // namespace nix