use super::*;
use crate::capture_invocation::capture_invocation_layout;
use crate::test_support::{fixture, git, git_context, git_text, remove};
use std::path::PathBuf;
fn oracle(name: &str, format: &str) -> (PathBuf, String, String) {
let root: PathBuf = fixture(name);
git(root.as_path(), &["init", "--quiet", format!("--object-format={format}").as_str()]);
let hashed: String = git_text(root.as_path(), &["hash-object", "-t", "tree", "--stdin"]);
let reported: String = git_text(root.as_path(), &["rev-parse", "--show-object-format"]);
return (root, hashed, reported);
}
#[test]
fn the_sha1_name_is_what_git_hashes() {
let (root, hashed, reported): (PathBuf, String, String) = oracle("empty-tree-sha1", "sha1");
assert_eq!(reported, "sha1");
assert_eq!(hashed, SHA1_EMPTY_TREE);
assert_eq!(empty_tree_name(reported.as_str()), Some(hashed.as_str()));
remove(root.as_path());
}
#[test]
fn the_sha256_name_is_what_git_hashes() {
let (root, hashed, reported): (PathBuf, String, String) = oracle("empty-tree-sha256", "sha256");
assert_eq!(reported, "sha256");
assert_eq!(hashed, SHA256_EMPTY_TREE);
assert_eq!(empty_tree_name(reported.as_str()), Some(hashed.as_str()));
assert_ne!(SHA1_EMPTY_TREE, SHA256_EMPTY_TREE);
remove(root.as_path());
}
#[test]
fn an_unknown_format_is_not_answered() {
assert_eq!(empty_tree_name("sha3"), None);
assert_eq!(empty_tree_name(""), None);
assert_eq!(empty_tree_name("SHA1"), None);
}
#[test]
fn the_capture_of_a_sha256_repository_records_the_sha256_empty_tree() {
let (root, hashed, _reported): (PathBuf, String, String) = oracle("empty-tree-capture-sha256", "sha256");
let layout = capture_invocation_layout(&git_context(), root.as_path(), false).expect("layout");
assert_eq!(layout.object_format, "sha256");
assert_eq!(layout.empty_tree_oid, hashed);
remove(root.as_path());
}