summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-04-07 11:50:57 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-04-07 11:50:57 +0200
commit108fef99d19ade71013dc25562e3c3c3e23347ef (patch)
treefd2082991d11fdbfe00c4345c0daec49e070c999
parentd7ac6f915079c2385be902106f97b994f5f65bc5 (diff)
Failing test for setting description
-rw-r--r--src/git.rs6
-rw-r--r--src/lib.rs8
-rw-r--r--src/parser.rs2
-rw-r--r--tests/cli.rs85
4 files changed, 78 insertions, 23 deletions
diff --git a/src/git.rs b/src/git.rs
index 3e6ef98..1271712 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -65,7 +65,11 @@ fn is_valid_git_repo_path(path: &PathBuf) -> Result<bool, ShackleError> {
}
}
-pub fn init(repo_name: &str, group: &Option<String>) -> Result<GitInitResult, ShackleError> {
+pub fn init(
+ repo_name: &str,
+ group: &Option<String>,
+ description: &Option<String>,
+) -> Result<GitInitResult, ShackleError> {
fn init_group(repo_name: &str, group: &str) -> Result<GitInitResult, ShackleError> {
if !verify_user_is_in_group(group) {
return Err(ShackleError::InvalidGroup);
diff --git a/src/lib.rs b/src/lib.rs
index 4685e53..7d4d2df 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -26,8 +26,12 @@ pub fn run_command(user_input: String) -> Result<ControlFlow<(), ()>, ShackleErr
println!("{table}");
}
- Ok(ShackleCommand::GitInit(GitInitArgs { repo_name, group })) => {
- let init_result = git::init(&repo_name, &group)?;
+ Ok(ShackleCommand::GitInit(GitInitArgs {
+ repo_name,
+ group,
+ description,
+ })) => {
+ let init_result = git::init(&repo_name, &group, &description)?;
println!("Successfully created \"{}\"", init_result.path.display());
}
Ok(ShackleCommand::GitUploadPack(upload_pack_args)) => {
diff --git a/src/parser.rs b/src/parser.rs
index 88b32bb..5295483 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -22,6 +22,8 @@ pub enum ShackleCommand {
pub struct GitInitArgs {
#[arg(long)]
pub group: Option<String>,
+ #[arg(long)]
+ pub description: Option<String>,
pub repo_name: String,
}
diff --git a/tests/cli.rs b/tests/cli.rs
index e64ce6b..dfbb915 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -225,15 +225,30 @@ fn allows_single_quotes_and_spaces_inside_double_quotes() -> Result<()> {
Ok(())
}
+const DEFAULT_DESCRIPTION: &str =
+ "Unnamed repository; edit this file 'description' to name the repository.";
+
+fn expect_list_table(c: &mut TestContext, repos: &[(String, String)]) -> Result<()> {
+ c.p.send_line("list")?;
+ c.p.exp_regex(r"\+-+\+-+\+")?;
+ c.p.exp_regex(r"\| path +\| description +\|")?;
+ c.p.exp_regex(r"\+=+\+")?;
+ for (path, description) in repos {
+ c.p.exp_string("| ")?;
+ c.p.exp_string(path)?;
+ c.p.exp_regex(r" +\| ")?;
+ c.p.exp_string(&description)?;
+ c.p.exp_regex(r" +\|")?;
+ }
+ c.p.exp_regex(r"\+-+\+-+\+")?;
+ expect_prompt(&mut c.p)?;
+ Ok(())
+}
+
#[test]
fn list_can_print_an_empty_list() -> Result<()> {
let mut c = spawn_interactive_process()?;
- c.p.send_line("list")?;
- c.p.exp_string("+------+-------------+")?;
- c.p.exp_string("| path | description |")?;
- c.p.exp_string("+====================+")?;
- c.p.exp_string("+------+-------------+")?;
- expect_prompt(&mut c.p)?;
+ expect_list_table(&mut c, &[])?;
Ok(())
}
@@ -245,13 +260,13 @@ fn list_can_print_a_list_of_personal_repos_with_descriptions() -> Result<()> {
let personal_repo_name = "my-personal-repo";
c.p.send_line(&format!("git-init {}", personal_repo_name))?;
- c.p.send_line("list")?;
- c.p.exp_regex(r"\+-+\+-+\+")?;
- c.p.exp_regex(r"\| path +\| description +\|")?;
- c.p.exp_regex(r"\+=+\+")?;
- c.p.exp_regex(&format!(r"\| git/{user}/{personal_repo_name}\.git +\| Unnamed repository; edit this file 'description' to name the repository\. +\|"))?;
- c.p.exp_regex(r"\+-+\+-+\+")?;
- expect_prompt(&mut c.p)?;
+ expect_list_table(
+ &mut c,
+ &[(
+ format!("git/{user}/{personal_repo_name}.git"),
+ DEFAULT_DESCRIPTION.to_owned(),
+ )],
+ )?;
Ok(())
}
@@ -267,13 +282,43 @@ fn list_can_print_a_list_of_all_repos_with_descriptions() -> Result<()> {
let shared_repo_name = "my-shared-repo";
c.p.send_line(&format!("git-init --group {} {}", group, shared_repo_name))?;
- c.p.send_line("list")?;
- c.p.exp_regex(r"\+-+\+-+\+")?;
- c.p.exp_regex(r"| path +| description +|")?;
- c.p.exp_regex(r"\+=+\+")?;
- c.p.exp_regex(&format!(r"\| git/{user}/{personal_repo_name}\.git +\| Unnamed repository; edit this file 'description' to name the repository\. +\|"))?;
- c.p.exp_regex(&format!(r"\| git/{group}/{shared_repo_name}\.git +\| Unnamed repository; edit this file 'description' to name the repository\. +\|"))?;
- c.p.exp_regex(r"\+-+\+-+\+")?;
+ expect_list_table(
+ &mut c,
+ &[
+ (
+ format!("git/{user}/{personal_repo_name}.git"),
+ DEFAULT_DESCRIPTION.to_owned(),
+ ),
+ (
+ format!("git/{group}/{shared_repo_name}.git"),
+ DEFAULT_DESCRIPTION.to_owned(),
+ ),
+ ],
+ )?;
+
+ Ok(())
+}
+
+#[test]
+fn can_set_the_description_on_a_repo_during_init() -> Result<()> {
+ let mut c = spawn_interactive_process()?;
+ let user = get_username().unwrap();
+ let repo_name = "my-personal-repo";
+ let description = "A cool repo that does cool things";
+ c.p.send_line(&format!(
+ "git-init --description \"{description}\" {repo_name}"
+ ))?;
+ c.p.exp_string(&format!(
+ "Successfully created \"git/{user}/{repo_name}.git\"",
+ ))?;
+
+ expect_list_table(
+ &mut c,
+ &[(
+ format!("git/{user}/{repo_name}.git"),
+ description.to_owned(),
+ )],
+ )?;
Ok(())
}