Added missing tests for getBlobSha1

Summary: Wrote tests for retrieving hashes from the object store and refactored existing tests. Includes positive and negative tests.

Reviewed By: strager, pkaush

Differential Revision: D15697488

fbshipit-source-id: 44aa8a36fbc1d1e56dcbbb6bcb665d3784cbb476
This commit is contained in:
Brian Strauch 2019-06-12 17:44:39 -07:00 committed by Facebook Github Bot
parent 13796362f5
commit 9090adaaa3

View File

@ -25,6 +25,14 @@ class ObjectStoreTest : public ::testing::Test {
objectStore_ = ObjectStore::create(localStore_, backingStore_);
}
Hash putReadyBlob(folly::StringPiece data) {
StoredBlob* storedBlob = backingStore_->putBlob(data);
storedBlob->setReady();
Blob blob = storedBlob->get();
return blob.getHash();
}
std::shared_ptr<LocalStore> localStore_;
std::shared_ptr<FakeBackingStore> backingStore_;
std::shared_ptr<ObjectStore> objectStore_;
@ -32,15 +40,11 @@ class ObjectStoreTest : public ::testing::Test {
TEST_F(ObjectStoreTest, getBlobSize) {
folly::StringPiece data = "A";
Hash id = putReadyBlob(data);
StoredBlob* storedBlob = backingStore_->putBlob(data);
storedBlob->setReady();
Blob blob = storedBlob->get();
Hash id = blob.getHash();
size_t expectedSize = data.size();
size_t size = objectStore_->getBlobSize(id).get();
EXPECT_EQ(data.size(), size);
EXPECT_EQ(expectedSize, size);
}
TEST_F(ObjectStoreTest, getBlobSizeNotFound) {
@ -51,3 +55,21 @@ TEST_F(ObjectStoreTest, getBlobSizeNotFound) {
std::domain_error,
"blob .* not found");
}
TEST_F(ObjectStoreTest, getBlobSha1) {
folly::StringPiece data = "A";
Hash id = putReadyBlob(data);
Hash expectedSha1 = Hash::sha1(data);
Hash sha1 = objectStore_->getBlobSha1(id).get();
EXPECT_EQ(expectedSha1.toString(), sha1.toString());
}
TEST_F(ObjectStoreTest, getBlobSha1NotFound) {
Hash id;
EXPECT_THROW_RE(
objectStore_->getBlobSha1(id).get(),
std::domain_error,
"blob .* not found");
}