// use super::*; #[tokio::test] async fn when_file_not_found_should_error() -> TestResult { //given let fs = given::a_filesystem(); let (mut open_repository, repo_details) = given::an_open_repository(&fs); open_repository .expect_read_file() .returning(|_, _| Err(git::file::Error::FileNotFound)); //when let_assert!( Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); assert!(matches!( err, actor::load::Error::File(git::file::Error::FileNotFound) )); Ok(()) } #[tokio::test] async fn when_file_format_invalid_should_error() -> TestResult { //given let fs = given::a_filesystem(); let (mut open_repository, repo_details) = given::an_open_repository(&fs); let contents = given::a_name(); // not a valid file content open_repository .expect_read_file() .return_once(move |_, _| Ok(contents)); //when let_assert!( Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); assert!(matches!(err, actor::load::Error::Toml(_))); Ok(()) } #[tokio::test] async fn when_main_branch_is_missing_should_error() -> TestResult { //given let fs = given::a_filesystem(); let (mut open_repository, repo_details) = given::an_open_repository(&fs); let branches = given::repo_branches(); let main = branches.main(); let next = branches.next(); let dev = branches.dev(); let contents = format!( r#" [branches] main = "{main}" next = "{next}" dev = "{dev}" "# ); open_repository .expect_read_file() .return_once(|_, _| Ok(contents)); let branches = vec![next, dev]; open_repository .expect_remote_branches() .return_once(move || Ok(branches)); //when let_assert!( Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); assert!(matches!(err, actor::load::Error::BranchNotFound(branch) if branch == main)); Ok(()) } #[tokio::test] async fn when_next_branch_is_missing_should_error() -> TestResult { //given let fs = given::a_filesystem(); let (mut open_repository, repo_details) = given::an_open_repository(&fs); let branches = given::repo_branches(); let main = branches.main(); let next = branches.next(); let dev = branches.dev(); let contents = format!( r#" [branches] main = "{main}" next = "{next}" dev = "{dev}" "# ); open_repository .expect_read_file() .return_once(|_, _| Ok(contents)); let branches = vec![main, dev]; open_repository .expect_remote_branches() .return_once(move || Ok(branches)); //when let_assert!( Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); assert!(matches!(err, actor::load::Error::BranchNotFound(branch) if branch == next)); Ok(()) } #[tokio::test] async fn when_dev_branch_is_missing_should_error() -> TestResult { //given let fs = given::a_filesystem(); let (mut open_repository, repo_details) = given::an_open_repository(&fs); let branches = given::repo_branches(); let main = branches.main(); let next = branches.next(); let dev = branches.dev(); let contents = format!( r#" [branches] main = "{main}" next = "{next}" dev = "{dev}" "# ); open_repository .expect_read_file() .return_once(move |_, _| Ok(contents)); let branches = vec![main, next]; open_repository .expect_remote_branches() .return_once(move || Ok(branches)); //when let_assert!( Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); assert!(matches!(err, actor::load::Error::BranchNotFound(branch) if branch == dev)); Ok(()) } #[tokio::test] async fn when_valid_file_should_return_repo_config() -> TestResult { //given let fs = given::a_filesystem(); let (mut open_repository, repo_details) = given::an_open_repository(&fs); let repo_config = given::a_repo_config(); let branches = repo_config.branches(); let main = branches.main(); let next = branches.next(); let dev = branches.dev(); let contents = format!( r#" [branches] main = "{main}" next = "{next}" dev = "{dev}" "# ); open_repository .expect_read_file() .return_once(move |_, _| Ok(contents)); let branches = vec![main, next, dev]; open_repository .expect_remote_branches() .return_once(move || Ok(branches)); //when let_assert!( Ok(result) = actor::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {result:?}"); assert_eq!(result, repo_config); Ok(()) }