summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-06-30 15:42:11 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-06-30 15:42:11 +0200
commit205bc70cb1bfc692f8e412d34c8452ac11aedceb (patch)
tree55bb51fa3915344c94f9f014c81b4586fb3353a6
parentd5bd938012edb5ea63e0eec5c79d2f38615b4527 (diff)
Move out common test data
-rw-r--r--tests/cli.rs84
1 files changed, 37 insertions, 47 deletions
diff --git a/tests/cli.rs b/tests/cli.rs
index 02f1f93..a814975 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -5,6 +5,9 @@ use shackle_shell::user_info::{get_user_groups, get_username};
use std::path::{Path, PathBuf};
use tempfile::TempDir;
+const REPO_NAME: &str = "my-repository";
+const REPO_NAME_2: &str = "my-other-repository";
+
struct TestContext {
p: PtySession,
workdir: TempDir,
@@ -162,15 +165,14 @@ fn verify_repo_config_value(repo_dir: &Path, config_key: &str, config_value: Opt
#[test]
fn can_init_a_new_git_repo() -> Result<()> {
let mut c = spawn_interactive_process()?;
- let repo_name = "my-new-repo";
- c.p.send_line(&format!("init {}", repo_name))?;
+ c.p.send_line(&format!("init {}", REPO_NAME))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- personal_repo_path(repo_name)
+ personal_repo_path(REPO_NAME)
))?;
expect_prompt(&mut c.p)?;
- let repo_dir = c.personal_repo_dir(repo_name);
+ let repo_dir = c.personal_repo_dir(REPO_NAME);
verify_repo_exists(&repo_dir);
verify_current_branch(&repo_dir, "refs/heads/main");
verify_repo_config_value(&repo_dir, "core.sharedrepository", None);
@@ -182,15 +184,14 @@ fn can_init_a_new_git_repo() -> Result<()> {
fn can_init_a_new_shared_git_repo() -> Result<()> {
let mut c = spawn_interactive_process()?;
let group = arbitrary_user_group();
- let repo_name = "my-new-shared-repo";
- c.p.send_line(&format!("init --group {} {}", group, repo_name))?;
+ c.p.send_line(&format!("init --group {} {}", group, REPO_NAME))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- group_repo_path(&group, repo_name)
+ group_repo_path(&group, REPO_NAME)
))?;
expect_prompt(&mut c.p)?;
- let repo_dir = c.group_repo_dir(&group, repo_name);
+ let repo_dir = c.group_repo_dir(&group, REPO_NAME);
verify_repo_exists(&repo_dir);
verify_repo_config_value(&repo_dir, "core.sharedrepository", Some("1"));
@@ -201,8 +202,7 @@ fn can_init_a_new_shared_git_repo() -> Result<()> {
fn does_not_init_shared_repo_if_the_user_isnt_in_the_group() -> Result<()> {
let mut c = spawn_interactive_process()?;
let group = "not-a-real-group";
- let repo_name = "my-new-shared-repo";
- c.p.send_line(&format!("init --group {} {}", group, repo_name))?;
+ c.p.send_line(&format!("init --group {} {}", group, REPO_NAME))?;
c.p.exp_string("Unknown group")?;
Ok(())
@@ -210,11 +210,10 @@ fn does_not_init_shared_repo_if_the_user_isnt_in_the_group() -> Result<()> {
#[test]
fn runs_a_single_command_and_exit_with_cli_flag() -> Result<()> {
- let repo_name = "another-new-repo";
- let mut c = run_batch_command(&format!("init {}", repo_name))?;
+ let mut c = run_batch_command(&format!("init {}", REPO_NAME))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- personal_repo_path(repo_name)
+ personal_repo_path(REPO_NAME)
))?;
c.p.exp_eof()?;
Ok(())
@@ -222,12 +221,11 @@ fn runs_a_single_command_and_exit_with_cli_flag() -> Result<()> {
#[test]
fn allows_quotes_arguments() -> Result<()> {
- let repo_name = "another-new-repo";
let mut c = spawn_interactive_process()?;
- c.p.send_line(&format!("\"init\" '{repo_name}'"))?;
+ c.p.send_line(&format!("\"init\" '{REPO_NAME}'"))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- personal_repo_path(repo_name)
+ personal_repo_path(REPO_NAME)
))?;
Ok(())
}
@@ -291,18 +289,17 @@ fn list_can_print_an_empty_list() -> Result<()> {
#[test]
fn list_can_print_a_list_of_personal_repos_with_descriptions() -> Result<()> {
let mut c = spawn_interactive_process()?;
- let repo_name = "my-personal-repo";
- c.p.send_line(&format!("init {}", repo_name))?;
+ c.p.send_line(&format!("init {}", REPO_NAME))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- personal_repo_path(repo_name)
+ personal_repo_path(REPO_NAME)
))?;
expect_prompt(&mut c.p)?;
expect_list_table(
&mut c,
&[(
- personal_repo_path(repo_name),
+ personal_repo_path(REPO_NAME),
DEFAULT_DESCRIPTION.to_owned(),
)],
)?;
@@ -313,20 +310,18 @@ fn list_can_print_a_list_of_personal_repos_with_descriptions() -> Result<()> {
#[test]
fn list_can_print_a_list_of_all_repos_with_descriptions() -> Result<()> {
let mut c = spawn_interactive_process()?;
- let personal_repo_name = "my-personal-repo";
- c.p.send_line(&format!("init {}", personal_repo_name))?;
+ c.p.send_line(&format!("init {}", REPO_NAME))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- personal_repo_path(personal_repo_name)
+ personal_repo_path(REPO_NAME)
))?;
expect_prompt(&mut c.p)?;
let group = arbitrary_user_group();
- let shared_repo_name = "my-shared-repo";
- c.p.send_line(&format!("init --group {} {}", group, shared_repo_name))?;
+ c.p.send_line(&format!("init --group {} {}", group, REPO_NAME_2))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- group_repo_path(&group, shared_repo_name)
+ group_repo_path(&group, REPO_NAME_2)
))?;
expect_prompt(&mut c.p)?;
@@ -334,11 +329,11 @@ fn list_can_print_a_list_of_all_repos_with_descriptions() -> Result<()> {
&mut c,
&[
(
- personal_repo_path(personal_repo_name),
+ personal_repo_path(REPO_NAME),
DEFAULT_DESCRIPTION.to_owned(),
),
(
- group_repo_path(&group, shared_repo_name),
+ group_repo_path(&group, REPO_NAME_2),
DEFAULT_DESCRIPTION.to_owned(),
),
],
@@ -350,17 +345,16 @@ fn list_can_print_a_list_of_all_repos_with_descriptions() -> Result<()> {
#[test]
fn can_set_the_description_on_a_repo_during_init() -> Result<()> {
let mut c = spawn_interactive_process()?;
- let repo_name = "my-personal-repo";
let description = "A cool repo that does cool things";
- c.p.send_line(&format!("init --description \"{description}\" {repo_name}"))?;
+ c.p.send_line(&format!("init --description \"{description}\" {REPO_NAME}"))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- personal_repo_path(repo_name)
+ personal_repo_path(REPO_NAME)
))?;
expect_list_table(
&mut c,
- &[(personal_repo_path(repo_name), description.to_owned())],
+ &[(personal_repo_path(REPO_NAME), description.to_owned())],
)?;
Ok(())
@@ -369,10 +363,9 @@ fn can_set_the_description_on_a_repo_during_init() -> Result<()> {
#[test]
fn can_change_the_description_on_a_repo() -> Result<()> {
let mut c = spawn_interactive_process()?;
- let repo_name = "my-personal-repo";
let description = "A cool repo that does cool things";
- let repo_path = personal_repo_path(repo_name);
- c.p.send_line(&format!("init {repo_name}"))?;
+ let repo_path = personal_repo_path(REPO_NAME);
+ c.p.send_line(&format!("init {REPO_NAME}"))?;
c.p.exp_string(&format!("Successfully created \"{repo_path}\"",))?;
c.p.send_line(&format!(
"set-description \"{repo_path}\" \"{description}\""
@@ -387,15 +380,14 @@ fn can_change_the_description_on_a_repo() -> Result<()> {
#[test]
fn can_set_the_main_branch_of_a_new_git_repo() -> Result<()> {
let mut c = spawn_interactive_process()?;
- let repo_name = "my-new-repo";
let main_branch = "foobar";
- c.p.send_line(&format!("init --branch {} {}", main_branch, repo_name))?;
+ c.p.send_line(&format!("init --branch {} {}", main_branch, REPO_NAME))?;
c.p.exp_string(&format!(
"Successfully created \"{}\"",
- personal_repo_path(repo_name)
+ personal_repo_path(REPO_NAME)
))?;
- let repo_dir = c.personal_repo_dir(repo_name);
+ let repo_dir = c.personal_repo_dir(REPO_NAME);
verify_current_branch(&repo_dir, &format!("refs/heads/{main_branch}"));
Ok(())
@@ -404,17 +396,16 @@ fn can_set_the_main_branch_of_a_new_git_repo() -> Result<()> {
#[test]
fn can_change_the_main_branch_on_a_repo() -> Result<()> {
let mut c = spawn_interactive_process()?;
- let repo_name = "my-new-repo";
let main_branch = "foobar";
- let repo_path = personal_repo_path(repo_name);
+ let repo_path = personal_repo_path(REPO_NAME);
- c.p.send_line(&format!("init {}", repo_name))?;
+ c.p.send_line(&format!("init {}", REPO_NAME))?;
c.p.exp_string(&format!("Successfully created \"{repo_path}\""))?;
c.p.send_line(&format!("set-branch \"{repo_path}\" \"{main_branch}\""))?;
c.p.exp_string("Successfully updated branch")?;
- let repo_dir = c.personal_repo_dir(repo_name);
+ let repo_dir = c.personal_repo_dir(REPO_NAME);
verify_current_branch(&repo_dir, &format!("refs/heads/{main_branch}"));
Ok(())
@@ -423,11 +414,10 @@ fn can_change_the_main_branch_on_a_repo() -> Result<()> {
#[test]
fn can_delete_a_repo() -> Result<()> {
let mut c = spawn_interactive_process()?;
- let repo_name = "an-old-repo";
- let repo_path = personal_repo_path(repo_name);
- let repo_dir = c.personal_repo_dir(repo_name);
+ let repo_path = personal_repo_path(REPO_NAME);
+ let repo_dir = c.personal_repo_dir(REPO_NAME);
- c.p.send_line(&format!("init {}", repo_name))?;
+ c.p.send_line(&format!("init {}", REPO_NAME))?;
c.p.exp_string(&format!("Successfully created \"{repo_path}\""))?;
verify_repo_exists(&repo_dir);