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 <grfn@gws.fyi>
This commit is contained in:
		
							parent
							
								
									010dba3495
								
							
						
					
					
						commit
						fea4df560b
					
				
					 1 changed files with 30 additions and 0 deletions
				
			
		
							
								
								
									
										30
									
								
								third_party/nix/src/tests/store_tests.cc
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										30
									
								
								third_party/nix/src/tests/store_tests.cc
									
										
									
									
										vendored
									
									
								
							|  | @ -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
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue