From fea4df560bdb9a14c3ea6d45aaad26a6a24d6ce5 Mon Sep 17 00:00:00 2001 From: Kane York Date: Fri, 14 Aug 2020 17:51:39 -0700 Subject: chore(tvix/tests): port upstream add.sh test Change-Id: I5151d142d6b2b7f1df37b170b0160b8f77a89120 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1755 Tested-by: BuildkiteCI Reviewed-by: glittershark --- third_party/nix/src/tests/store_tests.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'third_party/nix/src') 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(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 -- cgit 1.4.1