open Merge_queue let sample = {|{"mqschema":"1","branches":[],"targets":[],"runs":null,"hooks":null,"journal":[],"records":[],"rules":{"branch":"mq/config","commit":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","entry":"main","push":null,"sync":false},"landed":null,"dropped":null,"moved":null}|} let read s = match Status.Document.of_json s with | Ok x -> x | Error (`Msg m) -> Alcotest.fail m let test_codec () = let doc = read sample in Alcotest.(check string) "same document" sample (Status.Document.to_json doc); Alcotest.(check int) "no branches" 0 (List.length doc.branches); Alcotest.(check string) "rule entry" "main" doc.rules.entry; List.iter (fun s -> Alcotest.(check bool) "refuse changed document" true (Result.is_error (Status.Document.of_json s))) [ {|{"mqschema":"1","branches":[],"targets":[],"runs":null,"hooks":null,"journal":[],"records":[],"rules":{"branch":"mq/config","commit":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","entry":"main","push":null,"sync":false,"extra":0},"landed":null,"dropped":null,"moved":null}|}; {|{"mqschema":"1","mqschema":"1","branches":[],"targets":[],"runs":null,"hooks":null,"journal":[],"records":[],"rules":{"branch":"mq/config","commit":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","entry":"main","push":null,"sync":false},"landed":null,"dropped":null,"moved":null}|}; ] let suite = ("status_document", [ Alcotest.test_case "codec" `Quick test_codec ])