mirror of
https://github.com/facebook/sapling.git
synced 2024-09-11 10:36:52 +03:00
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:
parent
13796362f5
commit
9090adaaa3
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user