Files
radicle-git/radicle-git-ext/t/src/gen/commit/headers.rs
T
Fintan Halpenny b4ca7f31db test: improve commit and submodule testing
Two of the tests in radicle-git-ext and radicle-surf relied on using
the Git repository itself. This can end up being an issue when
sandboxing is involved.

This improves the situation by being able to generate commit data to
add to a temporary repository.

It also adds a helper for creating a local, temporary submodule for
testing the submodule interactions in the radicle-surf API.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-03-13 14:22:10 +00:00

31 lines
917 B
Rust

use proptest::{collection, prop_oneof, strategy::Strategy};
use radicle_git_ext::commit::headers::Headers;
use crate::gen;
pub fn headers() -> impl Strategy<Value = Headers> {
collection::vec(prop_oneof![header(), signature()], 0..5).prop_map(|hs| {
let mut headers = Headers::new();
for (k, v) in hs {
headers.push(&k, &v);
}
headers
})
}
fn header() -> impl Strategy<Value = (String, String)> {
(prop_oneof!["test", "foo", "foobar"], gen::alphanumeric())
}
pub fn signature() -> impl Strategy<Value = (String, String)> {
("gpgsig", prop_oneof![pgp(), ssh()])
}
pub fn pgp() -> impl Strategy<Value = String> {
"-----BEGIN PGP SIGNATURE-----\r?\n([A-Za-z0-9+/=\r\n]+)\r?\n-----END PGP SIGNATURE-----"
}
pub fn ssh() -> impl Strategy<Value = String> {
"-----BEGIN SSH SIGNATURE-----\r?\n([A-Za-z0-9+/=\r\n]+)\r?\n-----END SSH SIGNATURE-----"
}