From 1917ca1c4a20574ea1c79a38b057e8a6b96a8ec8 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 11 Dec 2024 11:52:40 +0100 Subject: [PATCH] bin: Add app test fixtures --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 3 ++- bin/main.rs | 2 ++ bin/test.rs | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 bin/test.rs diff --git a/Cargo.lock b/Cargo.lock index 5ce00e75..51f5ddd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1626,6 +1626,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "qcheck" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b439bd4242da51d62d18c95e6a6add749346756b0d1a587dfd0cc22fa6b5f3f0" +dependencies = [ + "rand", +] + [[package]] name = "quote" version = "1.0.35" @@ -1655,6 +1664,7 @@ dependencies = [ "multibase", "nonempty", "once_cell", + "qcheck", "radicle-cob", "radicle-crypto", "radicle-git-ext", @@ -1752,7 +1762,9 @@ dependencies = [ "amplify", "cyphernet", "ec25519", + "fastrand", "multibase", + "qcheck", "radicle-git-ext", "radicle-ssh", "serde", diff --git a/Cargo.toml b/Cargo.toml index e7a13e76..1e447dcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,4 +53,5 @@ tui-textarea = { version = "0.5.1", default-features = false, features = ["termi tui-tree-widget = { version = "0.21.0" } [dev-dependencies] -pretty_assertions = "^1.4.1" \ No newline at end of file +pretty_assertions = "^1.4.1" +radicle = { version = "0.14.0", features = ["test"]} \ No newline at end of file diff --git a/bin/main.rs b/bin/main.rs index 80bc5ab2..52c02188 100644 --- a/bin/main.rs +++ b/bin/main.rs @@ -3,6 +3,8 @@ mod commands; mod git; mod log; mod settings; +#[cfg(test)] +mod test; mod ui; use std::ffi::OsString; diff --git a/bin/test.rs b/bin/test.rs new file mode 100644 index 00000000..be392ccf --- /dev/null +++ b/bin/test.rs @@ -0,0 +1,35 @@ +pub mod fixtures { + use anyhow::Result; + + use radicle::cob::cache::NoCache; + use radicle::patch::{Cache, MergeTarget, PatchMut, Patches}; + use radicle::storage::git::Repository; + use radicle::test::setup::{BranchWith, NodeWithRepo}; + + pub fn node_with_repo() -> NodeWithRepo { + NodeWithRepo::default() + } + + pub fn branch(node: &NodeWithRepo) -> BranchWith { + let checkout = node.repo.checkout(); + checkout.branch_with([("README", b"Hello World!")]) + } + + pub fn patch<'a, 'g>( + node: &'a NodeWithRepo, + branch: &BranchWith, + patches: &'a mut Cache, NoCache>, + ) -> Result> { + let patch = patches.create( + "My first patch", + "Blah blah blah.", + MergeTarget::Delegates, + branch.base, + branch.oid, + &[], + &node.signer, + )?; + + Ok(patch) + } +}