From 5a4d0fff3fe3107441b93a7812ccfbffe11ed445 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Thu, 20 Apr 2023 21:09:39 +0200 Subject: [PATCH] tests: add radicle command test for the rad remote Signed-off-by: Vincenzo Palazzo --- radicle-cli/examples/rad-remote.md | 37 ++++++++++++++++++++++++++ radicle-cli/src/commands.rs | 2 ++ radicle-cli/src/commands/remote/add.rs | 5 +--- radicle-cli/src/main.rs | 6 +++++ radicle-cli/tests/commands.rs | 33 +++++++++++++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 radicle-cli/examples/rad-remote.md diff --git a/radicle-cli/examples/rad-remote.md b/radicle-cli/examples/rad-remote.md new file mode 100644 index 00000000..51f5261f --- /dev/null +++ b/radicle-cli/examples/rad-remote.md @@ -0,0 +1,37 @@ +Now, let's add a bob as a new remote: + +``` +$ rad remote add did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk --name bob +✓ Remote bob added with rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk +``` + +Now, we can see that there is a new remote in the list of remotes: + +``` +$ rad remote list +❲fetch❳ bob z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk +❲fetch❳ rad z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi +``` + +You can see both `bob` and `rad` as remotes. The `rad` remote is our personal remote of the project. + +When we're finished with the `bob` remote, we can remove it: + +``` +$ rad remote rm bob +✓ Remote `bob` removed +``` + +Now, add another time `bob` but without specify the `name`, so we should be able to fetch the node alias from our db! + +``` +$ rad remote add did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk +✓ Remote bob added with rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk +``` + +and then we remove again remote just added + +``` +$ rad remote rm bob +✓ Remote `bob` removed +``` diff --git a/radicle-cli/src/commands.rs b/radicle-cli/src/commands.rs index 746e683c..621ae673 100644 --- a/radicle-cli/src/commands.rs +++ b/radicle-cli/src/commands.rs @@ -38,6 +38,8 @@ pub mod rad_patch; pub mod rad_path; #[path = "commands/push.rs"] pub mod rad_push; +#[path = "commands/remote.rs"] +pub mod rad_remote; #[path = "commands/review.rs"] pub mod rad_review; #[path = "commands/rm.rs"] diff --git a/radicle-cli/src/commands/remote/add.rs b/radicle-cli/src/commands/remote/add.rs index 350e0807..8582f12e 100644 --- a/radicle-cli/src/commands/remote/add.rs +++ b/radicle-cli/src/commands/remote/add.rs @@ -23,10 +23,7 @@ pub fn run( let url = Url::from(id).with_namespace(*pubkey); let remote = add_remote(repository, &name, &url)?; - term::success!( - "Remote {} added with {url}", - remote.name, - ); + term::success!("Remote {} added with {url}", remote.name,); Ok(()) } diff --git a/radicle-cli/src/main.rs b/radicle-cli/src/main.rs index 0e4aee72..bc4ab49c 100644 --- a/radicle-cli/src/main.rs +++ b/radicle-cli/src/main.rs @@ -337,6 +337,12 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option> rad_web::run, args.to_vec(), ), + "remote" => term::run_command_args::( + rad_remote::HELP, + "Remote", + rad_remote::run, + args.to_vec(), + ), _ => { let exe = format!("{NAME}-{exe}"); let status = process::Command::new(exe.clone()).args(args).status(); diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index f7a18726..07423946 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -639,6 +639,39 @@ fn test_replication_via_seed() { .unwrap(); } +#[test] +fn rad_remote() { + let mut environment = Environment::new(); + let alice = environment.node("alice"); + let bob = environment.node("bob"); + let working = environment.tmp().join("working"); + let home = alice.home.clone(); + // Setup a test repository. + fixtures::repository(working.join("alice")); + + test( + "examples/rad-init.md", + working.join("alice"), + Some(&home), + [], + ) + .unwrap(); + + let mut alice = alice.spawn(Config::default()); + alice + .handle + .track_node(bob.id, Some("bob".to_owned())) + .unwrap(); + + test( + "examples/rad-remote.md", + working.join("alice"), + Some(&home), + [], + ) + .unwrap(); +} + #[test] fn rad_workflow() { let mut environment = Environment::new();