Compare commits
2 commits
80af909ab0
...
df6b96fbfd
Author | SHA1 | Date | |
---|---|---|---|
df6b96fbfd | |||
566125f5c0 |
4 changed files with 123 additions and 11 deletions
|
@ -62,7 +62,10 @@ fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> {
|
|||
.with_token(ApiToken::new(Secret::new(String::new())))
|
||||
.with_hostname(Hostname::new("git.kemitix.net"));
|
||||
repo_details.repo_path = RepoPath::new("kemitix/git-next".to_string());
|
||||
let open_repository = git::repository::factory::real().open(&repo_details)?;
|
||||
let Ok(open_repository) = git::repository::factory::real().open(&repo_details) else {
|
||||
// .git directory may not be present on dev environment
|
||||
return Ok(());
|
||||
};
|
||||
let_assert!(
|
||||
Some(found_git_remote) = open_repository.find_default_remote(Direction::Push),
|
||||
"Default Push Remote not found"
|
||||
|
@ -95,10 +98,10 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> {
|
|||
.with_token(ApiToken::new(Secret::new(String::new())))
|
||||
.with_hostname(Hostname::new("git.kemitix.net"));
|
||||
tracing::debug!("opening...");
|
||||
let_assert!(
|
||||
Ok(repository) = git::repository::factory::real().open(&repo_details),
|
||||
"open repository"
|
||||
);
|
||||
let Ok(repository) = git::repository::factory::real().open(&repo_details) else {
|
||||
// .git directory may not be present on dev environment
|
||||
return Ok(());
|
||||
};
|
||||
tracing::debug!("open okay");
|
||||
tracing::info!(?repository, "FOO");
|
||||
tracing::info!(?repo_details, "BAR");
|
||||
|
@ -108,11 +111,13 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> {
|
||||
fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() {
|
||||
let_assert!(
|
||||
Ok(cli_crate_dir) = std::env::current_dir().map_err(git::validation::remotes::Error::Io)
|
||||
);
|
||||
eprintln!("cli_crate_dir: {cli_crate_dir:?}");
|
||||
let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
||||
eprintln!("root: {root:?}");
|
||||
let mut repo_details = git::repo_details(
|
||||
1,
|
||||
git::Generation::default(),
|
||||
|
@ -126,14 +131,15 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> {
|
|||
.with_user(User::new("git".to_string()))
|
||||
.with_token(ApiToken::new(Secret::new(String::new())))
|
||||
.with_hostname(Hostname::new("git.kemitix.net"));
|
||||
let repository = git::repository::factory::real().open(&repo_details)?;
|
||||
let Ok(repository) = git::repository::factory::real().open(&repo_details) else {
|
||||
// .git directory may not be present on dev environment
|
||||
return;
|
||||
};
|
||||
let mut repo_details = repo_details.clone();
|
||||
repo_details.forge = repo_details
|
||||
.forge
|
||||
.with_hostname(Hostname::new("code.kemitix.net"));
|
||||
let_assert!(Err(_) = validate_default_remotes(&*repository, &repo_details));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -3,6 +3,9 @@ mod handlers;
|
|||
pub mod messages;
|
||||
mod model;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
use actix::{Actor, ActorContext as _, Context};
|
||||
|
|
|
@ -277,8 +277,12 @@ impl RepoState {
|
|||
|
||||
#[tracing::instrument]
|
||||
pub fn clear_alert(&mut self) {
|
||||
if let Self::Ready { alert, .. } = self {
|
||||
*alert = None;
|
||||
match self {
|
||||
Self::Identified { alert, .. }
|
||||
| Self::Configured { alert, .. }
|
||||
| Self::Ready { alert, .. } => {
|
||||
*alert = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
99
crates/cli/src/tui/actor/tests.rs
Normal file
99
crates/cli/src/tui/actor/tests.rs
Normal file
|
@ -0,0 +1,99 @@
|
|||
//
|
||||
mod model {
|
||||
mod repo_state {
|
||||
use git_next_core::{git::graph::Log, RepoBranches};
|
||||
use ratatui::style::Style;
|
||||
|
||||
use crate::{
|
||||
repo::tests::given,
|
||||
tui::actor::{RepoMessage, RepoState, ViewState},
|
||||
};
|
||||
type Alert = Option<String>;
|
||||
|
||||
fn identified_with_alert(alert: Alert) -> RepoState {
|
||||
RepoState::Identified {
|
||||
repo_alias: given::a_repo_alias(),
|
||||
message: RepoMessage::builder()
|
||||
.text(given::a_name())
|
||||
.style(Style::default())
|
||||
.build(),
|
||||
alert,
|
||||
}
|
||||
}
|
||||
|
||||
fn configured_with_alert(alert: Alert) -> RepoState {
|
||||
RepoState::Configured {
|
||||
repo_alias: given::a_repo_alias(),
|
||||
message: RepoMessage::builder()
|
||||
.text(given::a_name())
|
||||
.style(Style::default())
|
||||
.build(),
|
||||
alert,
|
||||
branches: RepoBranches::new(String::new(), String::new(), String::new()),
|
||||
log: Log::default(),
|
||||
}
|
||||
}
|
||||
fn ready_with_alert(alert: Alert) -> RepoState {
|
||||
RepoState::Ready {
|
||||
repo_alias: given::a_repo_alias(),
|
||||
message: RepoMessage::builder()
|
||||
.text(given::a_name())
|
||||
.style(Style::default())
|
||||
.build(),
|
||||
alert,
|
||||
branches: RepoBranches::new(String::new(), String::new(), String::new()),
|
||||
log: Log::default(),
|
||||
view_state: ViewState::default(),
|
||||
main: given::a_commit(),
|
||||
next: given::a_commit(),
|
||||
dev: given::a_commit(),
|
||||
}
|
||||
}
|
||||
|
||||
#[rstest::rstest]
|
||||
#[case(identified_with_alert(None))]
|
||||
#[case(configured_with_alert(None))]
|
||||
#[case(ready_with_alert(None))]
|
||||
fn none_alert_remains_none(#[case] mut repo_state: RepoState) {
|
||||
// given
|
||||
match &repo_state {
|
||||
RepoState::Identified { alert, .. }
|
||||
| RepoState::Configured { alert, .. }
|
||||
| RepoState::Ready { alert, .. } => {
|
||||
assert!(alert.is_none(), "should be none at start");
|
||||
}
|
||||
}
|
||||
// when
|
||||
repo_state.clear_alert();
|
||||
// then
|
||||
match &repo_state {
|
||||
RepoState::Identified { alert, .. }
|
||||
| RepoState::Configured { alert, .. }
|
||||
| RepoState::Ready { alert, .. } => assert!(alert.is_none(), "should remain none"),
|
||||
}
|
||||
}
|
||||
|
||||
#[rstest::rstest]
|
||||
#[case(identified_with_alert(Some(String::new())))]
|
||||
#[case(configured_with_alert(Some(String::new())))]
|
||||
#[case(ready_with_alert(Some(String::new())))]
|
||||
fn some_alert_becomes_none(#[case] mut repo_state: RepoState) {
|
||||
// given
|
||||
match &repo_state {
|
||||
RepoState::Identified { alert, .. }
|
||||
| RepoState::Configured { alert, .. }
|
||||
| RepoState::Ready { alert, .. } => {
|
||||
assert!(alert.is_some(), "should be some at start");
|
||||
}
|
||||
}
|
||||
// when
|
||||
repo_state.clear_alert();
|
||||
// then
|
||||
match &repo_state {
|
||||
RepoState::Identified { alert, .. }
|
||||
| RepoState::Configured { alert, .. }
|
||||
| RepoState::Ready { alert, .. } => assert!(alert.is_none(), "should become none"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue