git-next/crates/repo-actor/src/tests/branch/advance_next.rs
Paul Campbell fa5fa809d9
Some checks failed
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
Rust / build (push) Has been cancelled
ci/woodpecker/push/tag-created Pipeline was successful
refactor: merge git create into core crate
2024-07-26 07:59:37 +01:00

168 lines
6 KiB
Rust

//
use super::*;
mod when_at_dev {
// next and dev branches are the same
use super::*;
#[test]
fn should_not_push() -> TestResult {
let next = given::a_commit();
let dev_commit_history = &[next.clone()];
let fs = given::a_filesystem();
let repo_config = given::a_repo_config();
let (open_repository, repo_details) = given::an_open_repository(&fs);
// no on_push defined - so any call to push will cause an error
let message_token = given::a_message_token();
let_assert!(
Err(err) = crate::branch::advance_next(
&next,
dev_commit_history,
repo_details,
repo_config,
&open_repository,
message_token,
)
);
tracing::debug!("Got: {err}");
assert!(matches!(err, crate::branch::Error::NextAtDev));
Ok(())
}
}
mod can_advance {
// dev has at least one commit ahead of next
use super::*;
mod to_wip_commit {
// commit on dev is either invalid message or a WIP
use super::*;
#[test]
fn should_not_push() -> TestResult {
let next = given::a_commit();
let dev = given::a_commit_with_message("wip: test: message".to_string());
let dev_commit_history = &[dev, next.clone()];
let fs = given::a_filesystem();
let repo_config = given::a_repo_config();
let (open_repository, repo_details) = given::an_open_repository(&fs);
// no on_push defined - so any call to push will cause an error
let message_token = given::a_message_token();
let_assert!(
Err(err) = crate::branch::advance_next(
&next,
dev_commit_history,
repo_details,
repo_config,
&open_repository,
message_token,
)
);
tracing::debug!("Got: {err}");
assert!(matches!(err, crate::branch::Error::IsWorkInProgress));
Ok(())
}
}
mod to_invalid_commit {
// commit on dev is either invalid message or a WIP
use super::*;
#[test]
fn should_not_push_and_error() -> TestResult {
let next = given::a_commit();
let dev = given::a_commit();
let dev_commit_history = &[dev, next.clone()];
let fs = given::a_filesystem();
let repo_config = given::a_repo_config();
let (open_repository, repo_details) = given::an_open_repository(&fs);
// no on_push defined - so any call to push will cause an error
let message_token = given::a_message_token();
let_assert!(
Err(err) = crate::branch::advance_next(
&next,
dev_commit_history,
repo_details,
repo_config,
&open_repository,
message_token,
)
);
tracing::debug!("Got: {err}");
assert!(matches!(
err,
crate::branch::Error::InvalidCommitMessage{reason}
if reason == "Missing type in the commit summary, expected `type: description`"
));
Ok(())
}
}
mod to_valid_commit {
// commit on dev is valid conventional commit message
use super::*;
mod push_is_err {
// the git push command fails
use super::*;
#[test]
fn should_error() -> TestResult {
let next = given::a_commit();
let dev = given::a_commit_with_message("test: message".to_string());
let dev_commit_history = &[dev, next.clone()];
let fs = given::a_filesystem();
let repo_config = given::a_repo_config();
let (mut open_repository, repo_details) = given::an_open_repository(&fs);
expect::fetch_ok(&mut open_repository);
expect::push(&mut open_repository, Err(git::push::Error::Lock));
let message_token = given::a_message_token();
let_assert!(
Err(err) = crate::branch::advance_next(
&next,
dev_commit_history,
repo_details,
repo_config,
&open_repository,
message_token,
)
);
tracing::debug!("Got: {err:?}");
assert!(matches!(
err,
crate::branch::Error::Push(git::push::Error::Lock)
));
Ok(())
}
}
mod push_is_ok {
// the git push command succeeds
use super::*;
#[test]
fn should_ok() -> TestResult {
let next = given::a_commit();
let dev = given::a_commit_with_message("test: message".to_string());
let dev_commit_history = &[dev, next.clone()];
let fs = given::a_filesystem();
let repo_config = given::a_repo_config();
let (mut open_repository, repo_details) = given::an_open_repository(&fs);
expect::fetch_ok(&mut open_repository);
expect::push_ok(&mut open_repository);
let message_token = given::a_message_token();
let_assert!(
Ok(mt) = crate::branch::advance_next(
&next,
dev_commit_history,
repo_details,
repo_config,
&open_repository,
message_token,
)
);
tracing::debug!("Got: {mt:?}");
assert_eq!(mt, message_token);
Ok(())
}
}
}
}