diff options
author | Kane York <kanepyork@gmail.com> | 2020-08-15T00·51-0700 |
---|---|---|
committer | kanepyork <rikingcoding@gmail.com> | 2020-08-18T03·58+0000 |
commit | fea4df560bdb9a14c3ea6d45aaad26a6a24d6ce5 (patch) | |
tree | db72358121ac0994e700e81fd921f8fa674f21f9 /third_party/nix/src/tests/store_tests.cc | |
parent | 010dba3495c7e761fe24f77ec1af3b5e08d69ca1 (diff) |
chore(tvix/tests): port upstream add.sh test r/1672
Change-Id: I5151d142d6b2b7f1df37b170b0160b8f77a89120 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1755 Tested-by: BuildkiteCI Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/tests/store_tests.cc')
-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 |