surf: test serialization of tree

Confirm that the serialization of `source::Tree` has the expected
output.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2022-12-16 11:37:59 +00:00
parent 95c31f2a8e
commit 0d5b6c4c30
2 changed files with 42 additions and 0 deletions
+3
View File
@@ -6,3 +6,6 @@ mod git;
#[cfg(test)]
mod file_system;
#[cfg(test)]
mod source;
+39
View File
@@ -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)
}