Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): don't check last commit #619

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions git-cliff-core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ impl Repository {
mod test {
use super::*;
use crate::commit::Commit as AppCommit;
use git_conventional::ErrorKind;
use std::env;
use std::process::Command;
use std::str;
Expand Down Expand Up @@ -239,42 +238,36 @@ mod test {
.to_string())
}

#[test]
fn git_log() -> Result<()> {
let repository = Repository::init(
fn get_repository() -> Result<Repository> {
Repository::init(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("parent directory not found")
.to_path_buf(),
)?;
)
}

#[test]
fn get_latest_commit() -> Result<()> {
let repository = get_repository()?;
let commits = repository.commits(None, None, None)?;
let last_commit =
AppCommit::from(&commits.first().expect("no commits found").clone());
assert_eq!(get_last_commit_hash()?, last_commit.id);
if let Err(e) = last_commit.into_conventional() {
match e {
Error::ParseError(e) => {
eprintln!("\nthe last commit is not conventional\n");
assert_eq!(ErrorKind::InvalidFormat, e.kind())
}
_ => {
unreachable!()
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this check. I'm sure that the ability to parse a commit to conventional is well tested elsewhere.

Ok(())
}

#[test]
fn get_latest_tag() -> Result<()> {
let repository = get_repository()?;
let tags = repository.tags(&None, false)?;
assert_eq!(&get_last_tag()?, tags.last().expect("no tags found").1);
Ok(())
}

#[test]
fn git_tags() -> Result<()> {
let repository = Repository::init(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("parent directory not found")
.to_path_buf(),
)?;
let repository = get_repository()?;
let tags = repository.tags(&None, true)?;
assert_eq!(
tags.get("2b8b4d3535f29231e05c3572e919634b9af907b6").expect(
Expand Down Expand Up @@ -308,12 +301,7 @@ mod test {

#[test]
fn git_upstream_remote() -> Result<()> {
let repository = Repository::init(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("parent directory not found")
.to_path_buf(),
)?;
let repository = get_repository()?;
let remote = repository.upstream_remote()?;
assert_eq!(
Remote {
Expand Down
Loading