| |
use std::env;
|
| |
use std::path::Path;
|
| |
|
| + |
use radicle::crypto::ssh::Keystore;
|
| + |
use radicle::crypto::KeyPair;
|
| |
use radicle::profile::{Home, Profile};
|
| + |
use radicle::storage::git::transport;
|
| + |
use radicle::storage::git::Storage;
|
| |
use radicle::test::fixtures;
|
| |
|
| |
mod framework;
|
| |
use framework::TestFormula;
|
| + |
use radicle_crypto::Seed;
|
| + |
|
| + |
/// Test environment.
|
| + |
pub struct Environment {
|
| + |
tempdir: tempfile::TempDir,
|
| + |
users: usize,
|
| + |
}
|
| + |
|
| + |
impl Environment {
|
| + |
/// Create a new test environment.
|
| + |
fn new() -> Self {
|
| + |
Self {
|
| + |
tempdir: tempfile::tempdir().unwrap(),
|
| + |
users: 0,
|
| + |
}
|
| + |
}
|
| + |
|
| + |
/// Create a new profile in this environment.
|
| + |
fn profile(&mut self, name: &str) -> Profile {
|
| + |
let home = Home::new(self.tempdir.path().join(name)).init().unwrap();
|
| + |
let storage = Storage::open(home.storage()).unwrap();
|
| + |
let keystore = Keystore::new(&home.keys());
|
| + |
let keypair = KeyPair::from_seed(Seed::from([!(self.users as u8); 32]));
|
| + |
|
| + |
transport::local::register(storage.clone());
|
| + |
keystore
|
| + |
.store(keypair.clone(), "radicle", "radicle".to_owned())
|
| + |
.unwrap();
|
| + |
|
| + |
// Ensures that each user has a unique but deterministic public key.
|
| + |
self.users += 1;
|
| + |
|
| + |
Profile {
|
| + |
home,
|
| + |
storage,
|
| + |
keystore,
|
| + |
public_key: keypair.pk.into(),
|
| + |
}
|
| + |
}
|
| + |
}
|
| |
|
| |
/// Run a CLI test file.
|
| - |
fn test(
|
| + |
fn test<'a>(
|
| |
test: impl AsRef<Path>,
|
| |
cwd: impl AsRef<Path>,
|
| - |
profile: Option<&Profile>,
|
| + |
home: Option<&Home>,
|
| + |
envs: impl IntoIterator<Item = (&'a str, &'a str)>,
|
| |
) -> Result<(), Box<dyn std::error::Error>> {
|
| |
let base = Path::new(env!("CARGO_MANIFEST_DIR"));
|
| |
let tmp = tempfile::tempdir().unwrap();
|
| - |
let home = if let Some(profile) = profile {
|
| - |
profile.home().to_path_buf()
|
| + |
let home = if let Some(home) = home {
|
| + |
home.path().to_path_buf()
|
| |
} else {
|
| |
tmp.path().to_path_buf()
|
| |
};
|
| |
Ok(())
|
| |
}
|
| |
|
| - |
/// Create a new user profile.
|
| - |
fn profile(home: &Path) -> Profile {
|
| - |
// Set debug mode, to make test output more predictable.
|
| - |
env::set_var("RAD_DEBUG", "1");
|
| - |
// Setup a new user.
|
| - |
Profile::init(Home::new(home.to_path_buf()), "radicle".to_owned()).unwrap()
|
| - |
}
|
| - |
|
| |
#[test]
|
| |
fn rad_auth() {
|
| - |
test("examples/rad-auth.md", Path::new("."), None).unwrap();
|
| + |
test(
|
| + |
"examples/rad-auth.md",
|
| + |
Path::new("."),
|
| + |
None,
|
| + |
[("RAD_DEBUG", "1")],
|
| + |
)
|
| + |
.unwrap();
|
| |
}
|
| |
|
| |
#[test]
|
| |
fn rad_issue() {
|
| - |
let home = tempfile::tempdir().unwrap();
|
| + |
let mut environment = Environment::new();
|
| + |
let profile = environment.profile("alice");
|
| + |
let home = &profile.home;
|
| |
let working = tempfile::tempdir().unwrap();
|
| - |
let profile = profile(home.path());
|
| |
|
| |
// Setup a test repository.
|
| |
fixtures::repository(working.path());
|
| |
// Set a fixed commit time.
|
| |
env::set_var(radicle_cob::git::RAD_COMMIT_TIME, "1671125284");
|
| |
|
| - |
test("examples/rad-init.md", working.path(), Some(&profile)).unwrap();
|
| - |
test("examples/rad-issue.md", working.path(), Some(&profile)).unwrap();
|
| + |
test("examples/rad-init.md", working.path(), Some(home), []).unwrap();
|
| + |
test("examples/rad-issue.md", working.path(), Some(home), []).unwrap();
|
| |
}
|
| |
|
| |
#[test]
|
| |
fn rad_init() {
|
| - |
let home = tempfile::tempdir().unwrap();
|
| + |
let mut environment = Environment::new();
|
| + |
let profile = environment.profile("alice");
|
| |
let working = tempfile::tempdir().unwrap();
|
| - |
let profile = profile(home.path());
|
| |
|
| |
// Setup a test repository.
|
| |
fixtures::repository(working.path());
|
| |
|
| - |
test("examples/rad-init.md", working.path(), Some(&profile)).unwrap();
|
| + |
test(
|
| + |
"examples/rad-init.md",
|
| + |
working.path(),
|
| + |
Some(&profile.home),
|
| + |
[],
|
| + |
)
|
| + |
.unwrap();
|
| |
}
|
| |
|
| |
#[test]
|
| |
fn rad_delegate() {
|
| - |
let home = tempfile::tempdir().unwrap();
|
| + |
let mut environment = Environment::new();
|
| + |
let profile = environment.profile("alice");
|
| |
let working = tempfile::tempdir().unwrap();
|
| - |
let profile = profile(home.path());
|
| + |
let home = &profile.home;
|
| |
|
| |
// Setup a test repository.
|
| |
fixtures::repository(working.path());
|
| |
|
| - |
test("examples/rad-init.md", working.path(), Some(&profile)).unwrap();
|
| - |
test("examples/rad-delegate.md", working.path(), Some(&profile)).unwrap();
|
| + |
test("examples/rad-init.md", working.path(), Some(home), []).unwrap();
|
| + |
test("examples/rad-delegate.md", working.path(), Some(home), []).unwrap();
|
| |
}
|
| |
|
| |
#[test]
|
| |
#[ignore]
|
| |
fn rad_patch() {
|
| - |
let home = tempfile::tempdir().unwrap();
|
| + |
let mut environment = Environment::new();
|
| + |
let profile = environment.profile("alice");
|
| |
let working = tempfile::tempdir().unwrap();
|
| - |
let profile = profile(home.path());
|
| + |
let home = &profile.home;
|
| |
|
| |
// Setup a test repository.
|
| |
fixtures::repository(working.path());
|
| |
|
| - |
test("examples/rad-init.md", working.path(), Some(&profile)).unwrap();
|
| - |
test("examples/rad-issue.md", working.path(), Some(&profile)).unwrap();
|
| - |
test("examples/rad-patch.md", working.path(), Some(&profile)).unwrap();
|
| + |
test("examples/rad-init.md", working.path(), Some(home), []).unwrap();
|
| + |
test("examples/rad-issue.md", working.path(), Some(home), []).unwrap();
|
| + |
test("examples/rad-patch.md", working.path(), Some(home), []).unwrap();
|
| |
}
|