diff options
Diffstat (limited to '')
-rw-r--r-- | third_party/nix/src/tests/store_tests.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/third_party/nix/src/tests/store_tests.cc b/third_party/nix/src/tests/store_tests.cc index 936a0cee1b68..8110e9c337bc 100644 --- a/third_party/nix/src/tests/store_tests.cc +++ b/third_party/nix/src/tests/store_tests.cc @@ -88,4 +88,34 @@ TEST_F(BinaryCacheStoreTest, BasicErrors) { } } +// ./tests/add.sh +TEST_F(StoreTest, AddFileHashes) { + auto store_ = OpenTemporaryStore().ConsumeValueOrDie(); + nix::Store* store = static_cast<nix::Store*>(store_.get()); + nix::Path dataPath = NIX_SRC_DIR "/src/tests/lang/data"; + std::string dataName = "data"; + + nix::Path path1 = store->addToStore(dataName, dataPath); + + nix::Path path2 = store->addToStore(dataName, dataPath, /*recursive=*/true, + HashType::htSHA256); + + EXPECT_EQ(path1, path2) << "nix-store --add and --add-fixed mismatch"; + + nix::Path path3 = store->addToStore(dataName, dataPath, /*recursive=*/false, + HashType::htSHA256); + EXPECT_NE(path1, path3); + + nix::Path path4 = + store->addToStore(dataName, dataPath, false, HashType::htSHA1); + EXPECT_NE(path1, path4); + + auto info1 = store->queryPathInfo(store->followLinksToStorePath(path1)); + ASSERT_EQ(info1->narHash.type, HashType::htSHA256); + + Hash h = nix::hashPath(HashType::htSHA256, dataPath).first; + + EXPECT_EQ(info1->narHash.to_string(), h.to_string()); +} + } // namespace nix |