Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
at main 71 lines 2.4 kB view raw
1open Irmin 2 3let test_commit_fields () = 4 let tree_hash = Hash.sha1 "tree content" in 5 let c = 6 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice" 7 ~message:"Initial commit" () 8 in 9 Alcotest.(check string) "author" "Alice" (Commit.Git.author c); 10 Alcotest.(check string) "message" "Initial commit" (Commit.Git.message c); 11 Alcotest.(check (list (Alcotest.testable Hash.pp Hash.equal))) 12 "no parents" [] (Commit.Git.parents c); 13 Alcotest.(check bool) 14 "tree matches" true 15 (Hash.equal tree_hash (Commit.Git.tree c)) 16 17let test_commit_committer () = 18 let tree_hash = Hash.sha1 "tree" in 19 let c = 20 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice" ~committer:"Bob" 21 ~message:"test" () 22 in 23 Alcotest.(check string) "committer" "Bob" (Commit.Git.committer c) 24 25let test_commit_parents () = 26 let tree_hash = Hash.sha1 "tree" in 27 let parent1 = Hash.sha1 "parent1" in 28 let parent2 = Hash.sha1 "parent2" in 29 let c = 30 Commit.Git.v ~tree:tree_hash ~parents:[ parent1; parent2 ] ~author:"test" 31 ~message:"merge" () 32 in 33 Alcotest.(check int) "two parents" 2 (List.length (Commit.Git.parents c)) 34 35let test_commit_roundtrip () = 36 let tree_hash = Hash.sha1 "tree content" in 37 let c = 38 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice" 39 ~message:"test commit" () 40 in 41 let bytes = Commit.Git.to_bytes c in 42 match Commit.Git.of_bytes bytes with 43 | Ok c' -> 44 Alcotest.(check string) "author roundtrip" "Alice" (Commit.Git.author c'); 45 Alcotest.(check string) 46 "message roundtrip" "test commit" (Commit.Git.message c') 47 | Error (`Msg msg) -> Alcotest.fail msg 48 49let test_commit_hash () = 50 let tree_hash = Hash.sha1 "tree" in 51 let c1 = 52 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice" ~message:"same" 53 ~timestamp:1000L () 54 in 55 let c2 = 56 Commit.Git.v ~tree:tree_hash ~parents:[] ~author:"Alice" ~message:"same" 57 ~timestamp:1000L () 58 in 59 Alcotest.(check bool) 60 "same content same hash" true 61 (Hash.equal (Commit.Git.hash c1) (Commit.Git.hash c2)) 62 63let suite = 64 ( "Commit", 65 [ 66 Alcotest.test_case "fields" `Quick test_commit_fields; 67 Alcotest.test_case "committer" `Quick test_commit_committer; 68 Alcotest.test_case "parents" `Quick test_commit_parents; 69 Alcotest.test_case "roundtrip" `Quick test_commit_roundtrip; 70 Alcotest.test_case "hash" `Quick test_commit_hash; 71 ] )