Skip to content

Commit

Permalink
test: add test util git commands
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 16, 2020
1 parent ee63242 commit e4271db
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
2 changes: 0 additions & 2 deletions coco.toml
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
changelog_file = "CHANGELOG.md"
sort_commit = "by_type"
60 changes: 58 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl CocoGitto {
description,
is_breaking_change,
}
.to_string();
.to_string();

let oid = self.repository.commit(message)?;
let commit = self.repository.0.find_commit(oid)?;
Expand Down Expand Up @@ -379,8 +379,64 @@ impl CocoGitto {
}
}

#[cfg(test)]
use std::env::temp_dir;

#[cfg(test)]
fn git_init() -> Result<()> {
let temp_dir = temp_dir();
std::env::set_current_dir(temp_dir)?;
Command::new("git")
.arg("init")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()?;

Ok(())
}

#[cfg(test)]
fn git_commit(message: &str) -> Result<()> {
Command::new("git")
.arg("commit")
.arg("-m")
.arg(message)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()?;
Ok(())
}

#[cfg(test)]
fn git_tag(tag: &str) -> Result<()> {
Command::new("tag")
.arg(tag)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()?;
Ok(())
}

#[cfg(test)]
fn create_empty_config() -> Result<()> {
std::fs::File::create("coco.toml")?;
Ok(())
}


#[cfg(test)]
mod test {
use crate::{git_init, create_empty_config, CocoGitto};
use anyhow::Result;

#[test]
fn should_open_repo() {}
fn should_open_repo() -> Result<()> {
git_init()?;
create_empty_config()?;

let gitto = CocoGitto::get();

assert!(gitto.is_ok());
Ok(())
}
}

0 comments on commit e4271db

Please sign in to comment.