2024-06-19 07:03:08 +01:00
|
|
|
//
|
|
|
|
use super::*;
|
2024-06-27 21:10:41 +01:00
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
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) = actor::branch::advance_next(
|
|
|
|
&next,
|
|
|
|
dev_commit_history,
|
|
|
|
repo_details,
|
|
|
|
repo_config,
|
|
|
|
&open_repository,
|
|
|
|
message_token,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
tracing::debug!("Got: {err}");
|
|
|
|
assert!(matches!(err, actor::branch::Error::NextAtDev));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2024-06-27 21:10:41 +01:00
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
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::*;
|
2024-06-27 21:10:41 +01:00
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
#[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) = actor::branch::advance_next(
|
|
|
|
&next,
|
|
|
|
dev_commit_history,
|
|
|
|
repo_details,
|
|
|
|
repo_config,
|
|
|
|
&open_repository,
|
|
|
|
message_token,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
tracing::debug!("Got: {err}");
|
|
|
|
assert!(matches!(err, actor::branch::Error::IsWorkInProgress));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2024-06-27 21:10:41 +01:00
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
mod to_invalid_commit {
|
|
|
|
// commit on dev is either invalid message or a WIP
|
|
|
|
use super::*;
|
2024-06-27 21:10:41 +01:00
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
#[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) = actor::branch::advance_next(
|
|
|
|
&next,
|
|
|
|
dev_commit_history,
|
|
|
|
repo_details,
|
|
|
|
repo_config,
|
|
|
|
&open_repository,
|
|
|
|
message_token,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
tracing::debug!("Got: {err}");
|
|
|
|
assert!(matches!(
|
|
|
|
err,
|
|
|
|
actor::branch::Error::InvalidCommitMessage{reason}
|
|
|
|
if reason == "Missing type in the commit summary, expected `type: description`"
|
|
|
|
));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2024-06-27 21:10:41 +01:00
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
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) = actor::branch::advance_next(
|
|
|
|
&next,
|
|
|
|
dev_commit_history,
|
|
|
|
repo_details,
|
|
|
|
repo_config,
|
|
|
|
&open_repository,
|
|
|
|
message_token,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
tracing::debug!("Got: {err:?}");
|
|
|
|
assert!(matches!(
|
|
|
|
err,
|
|
|
|
actor::branch::Error::Push(git::push::Error::Lock)
|
|
|
|
));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2024-06-27 21:10:41 +01:00
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
mod push_is_ok {
|
|
|
|
// the git push command succeeds
|
|
|
|
use super::*;
|
2024-06-27 21:10:41 +01:00
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
#[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) = actor::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(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|