From 0d5b6c4c30dfebf343b5867ddb0907b8dfc62e2e Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 14 Dec 2022 13:40:53 +0000 Subject: [PATCH] surf: test serialization of tree Confirm that the serialization of `source::Tree` has the expected output. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-surf/t/src/lib.rs | 3 +++ radicle-surf/t/src/source.rs | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 radicle-surf/t/src/source.rs diff --git a/radicle-surf/t/src/lib.rs b/radicle-surf/t/src/lib.rs index fc9023d..c46d568 100644 --- a/radicle-surf/t/src/lib.rs +++ b/radicle-surf/t/src/lib.rs @@ -6,3 +6,6 @@ mod git; #[cfg(test)] mod file_system; + +#[cfg(test)] +mod source; diff --git a/radicle-surf/t/src/source.rs b/radicle-surf/t/src/source.rs new file mode 100644 index 0000000..5f098ee --- /dev/null +++ b/radicle-surf/t/src/source.rs @@ -0,0 +1,39 @@ +use std::path::Path; + +use git_ref_format::refname; +use radicle_surf::{git::Repository, source}; +use serde_json::json; + +const GIT_PLATINUM: &str = "../data/git-platinum"; + +#[test] +fn tree_serialization() { + let repo = Repository::open(GIT_PLATINUM).unwrap(); + let tree = source::Tree::new( + &repo, + &refname!("refs/heads/master"), + Some(&Path::new("src")), + ) + .unwrap(); + + let expected = json!({ + "entries": [ + { + "kind": "blob", + "lastCommit": null, + "name": "Eval.hs", + "path": "src/Eval.hs" + }, + { + "kind": "blob", + "lastCommit": null, + "name": "memory.rs", + "path": "src/memory.rs" + } + ], + "lastCommit": null, + "name": "src", + "path": "src" + }); + assert_eq!(serde_json::to_value(tree).unwrap(), expected) +}