Added a proper test for the overview
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
This commit is contained in:
parent
a002475a81
commit
ea7716b939
|
@ -0,0 +1,11 @@
|
|||
pub trait Print {
|
||||
fn println(&self, text: &str);
|
||||
}
|
||||
|
||||
pub struct Console;
|
||||
|
||||
impl Print for Console {
|
||||
fn println(&self, text: &str) {
|
||||
println!("{}", text);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
use rusqlite::Connection;
|
||||
|
||||
use crate::console::{Console, Print};
|
||||
use crate::list_overview::models::ListOverviewRequest;
|
||||
use crate::list_overview::OverviewHandler;
|
||||
use configuration::ArgumentParser;
|
||||
|
@ -12,6 +13,7 @@ use crate::register_origin::RegisterOriginHandler;
|
|||
use crate::routing::Router;
|
||||
|
||||
pub mod configuration;
|
||||
pub mod console;
|
||||
pub mod list_overview;
|
||||
pub mod register_current;
|
||||
pub mod register_origin;
|
||||
|
@ -40,16 +42,17 @@ pub struct Application<'a> {
|
|||
impl<'a> Application<'a> {
|
||||
pub fn new(
|
||||
settings: &'a Settings,
|
||||
console: &'a dyn Print,
|
||||
argument_parser: ArgumentParser,
|
||||
arguments: Vec<String>,
|
||||
) -> Application {
|
||||
) -> Application<'a> {
|
||||
Application {
|
||||
settings,
|
||||
argument_parser,
|
||||
arguments,
|
||||
register_origin_handler: register_origin::init(settings),
|
||||
register_current_handler: register_current::init(settings),
|
||||
overview_handler: list_overview::init(settings),
|
||||
overview_handler: list_overview::init(settings, console),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
use crate::list_overview::models::{Current, ListOverviewRequest, Origin};
|
||||
use crate::Settings;
|
||||
use crate::{Print, Settings};
|
||||
|
||||
pub fn init(settings: &Settings) -> OverviewHandler {
|
||||
pub fn init<'a>(settings: &'a Settings, console: &'a dyn Print) -> OverviewHandler<'a> {
|
||||
let overview_gateway = OverviewGateway::new(settings);
|
||||
OverviewHandler {
|
||||
settings,
|
||||
overview_gateway,
|
||||
console,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OverviewHandler<'a> {
|
||||
pub settings: &'a Settings,
|
||||
console: &'a dyn Print,
|
||||
overview_gateway: OverviewGateway<'a>,
|
||||
}
|
||||
|
||||
|
@ -24,7 +26,7 @@ impl<'a> OverviewHandler<'a> {
|
|||
|
||||
println!("All currents:");
|
||||
for current in currents {
|
||||
println!("{}", current.name);
|
||||
self.console.println(current.name.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
use application::configuration::{ArgumentParser, Settings};
|
||||
use application::register_origin;
|
||||
use application::console::Console;
|
||||
use application::Application;
|
||||
|
||||
fn main() {
|
||||
let parser = ArgumentParser {};
|
||||
let settings = Settings::new().unwrap();
|
||||
let application = Application::new(&settings, parser, std::env::args().collect());
|
||||
let console = Console {};
|
||||
let args = std::env::args().collect();
|
||||
let application = Application::new(&settings, &console, parser, args);
|
||||
|
||||
application.run();
|
||||
}
|
||||
|
|
|
@ -99,3 +99,23 @@ pub mod database {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod console {
|
||||
use application::console::Print;
|
||||
|
||||
pub struct FakeConsole<T>
|
||||
where
|
||||
T: Fn(),
|
||||
{
|
||||
pub callback: T,
|
||||
}
|
||||
|
||||
impl<T> Print for FakeConsole<T>
|
||||
where
|
||||
T: Fn(),
|
||||
{
|
||||
fn println(&self, text: &str) {
|
||||
(self.callback)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use application::configuration::{ArgumentParser, VcsType};
|
||||
use application::{migrate, Application};
|
||||
use serial_test::serial;
|
||||
use std::cell::Cell;
|
||||
use test_context::test_context;
|
||||
use test_utilities::console::FakeConsole;
|
||||
use test_utilities::{
|
||||
database::FunctionalTestContext, get_current, get_current_count, get_origin, get_origins_count,
|
||||
insert_current, insert_origin,
|
||||
|
@ -56,6 +58,17 @@ fn should_print_current(context: &FunctionalTestContext) {
|
|||
"github".to_string(),
|
||||
&context.settings.database.get_connection(),
|
||||
);
|
||||
let application = Application::new(&context.settings, parser, arguments);
|
||||
|
||||
let times_print_is_called = Cell::new(0);
|
||||
let fake_console = FakeConsole {
|
||||
callback: || {
|
||||
let mut called = times_print_is_called.get();
|
||||
called += 1;
|
||||
times_print_is_called.set(called);
|
||||
},
|
||||
};
|
||||
let application = Application::new(&context.settings, &fake_console, parser, arguments);
|
||||
application.run();
|
||||
|
||||
assert_eq!(3, times_print_is_called.get());
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ use serial_test::serial;
|
|||
use test_context::test_context;
|
||||
|
||||
use application::configuration::{ArgumentParser, Settings, VcsType};
|
||||
use application::console::Console;
|
||||
use application::{migrate, Application};
|
||||
use test_utilities::{
|
||||
database::FunctionalTestContext, get_current, get_current_count, get_origin, get_origins_count,
|
||||
|
@ -42,6 +43,7 @@ fn shoud_save_only_one_current(context: &FunctionalTestContext) {
|
|||
#[serial]
|
||||
fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
|
||||
let parser = ArgumentParser {};
|
||||
let console = Console {};
|
||||
let arguments = vec![
|
||||
String::from("release_checker"),
|
||||
String::from("register"),
|
||||
|
@ -58,7 +60,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
|
|||
&context.settings.database.get_connection(),
|
||||
);
|
||||
|
||||
let application = Application::new(&context.settings, parser, arguments);
|
||||
let application = Application::new(&context.settings, &console, parser, arguments);
|
||||
application.run();
|
||||
|
||||
let total_count_of_currents = get_origins_count(&context.settings.database.get_connection());
|
||||
|
@ -99,6 +101,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
|
|||
#[serial]
|
||||
fn should_route_to_current(context: &FunctionalTestContext) {
|
||||
let parser = ArgumentParser {};
|
||||
let console = Console {};
|
||||
let arguments = vec![
|
||||
String::from("release_checker"),
|
||||
String::from("register"),
|
||||
|
@ -107,6 +110,6 @@ fn should_route_to_current(context: &FunctionalTestContext) {
|
|||
String::from("name"),
|
||||
String::from("1"),
|
||||
];
|
||||
let application = Application::new(&context.settings, parser, arguments);
|
||||
let application = Application::new(&context.settings, &console, parser, arguments);
|
||||
application.run();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use application::configuration::{ArgumentParser, Settings, VcsType};
|
||||
use application::console::Console;
|
||||
use application::Application;
|
||||
use serial_test::serial;
|
||||
use test_context::test_context;
|
||||
|
@ -9,6 +10,7 @@ use test_utilities::{database::FunctionalTestContext, get_origin, get_origins_co
|
|||
#[serial]
|
||||
fn shoud_save_only_one_origin(context: &FunctionalTestContext) {
|
||||
let parser = ArgumentParser {};
|
||||
let console = Console {};
|
||||
let settings = Settings::new().unwrap();
|
||||
let arguments = vec![
|
||||
String::from("release_checker"),
|
||||
|
@ -18,7 +20,7 @@ fn shoud_save_only_one_origin(context: &FunctionalTestContext) {
|
|||
String::from("name"),
|
||||
String::from("https://url"),
|
||||
];
|
||||
let application = Application::new(&settings, parser, arguments);
|
||||
let application = Application::new(&settings, &console, parser, arguments);
|
||||
application.run();
|
||||
application.run();
|
||||
|
||||
|
@ -31,6 +33,7 @@ fn shoud_save_only_one_origin(context: &FunctionalTestContext) {
|
|||
#[serial]
|
||||
fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
|
||||
let parser = ArgumentParser {};
|
||||
let console = Console {};
|
||||
let settings = Settings::new().unwrap();
|
||||
let arguments = vec![
|
||||
String::from("release_checker"),
|
||||
|
@ -40,7 +43,9 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
|
|||
String::from("name"),
|
||||
String::from("https://url"),
|
||||
];
|
||||
let application = Application::new(&settings, parser, arguments);
|
||||
let application = Application::new(&settings, &console, parser, arguments);
|
||||
let console = Console {};
|
||||
let console = Console {};
|
||||
application.run();
|
||||
|
||||
let total_count_of_origins = get_origins_count(&settings.database.get_connection());
|
||||
|
@ -52,6 +57,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
|
|||
assert_eq!(origin.vcs_type, VcsType::Github);
|
||||
|
||||
let parser = ArgumentParser {};
|
||||
let console = Console {};
|
||||
let settings = Settings::new().unwrap();
|
||||
let arguments = vec![
|
||||
String::from("release_checker"),
|
||||
|
@ -61,7 +67,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
|
|||
String::from("name"),
|
||||
String::from("https://url_updated"),
|
||||
];
|
||||
let application = Application::new(&settings, parser, arguments);
|
||||
let application = Application::new(&settings, &console, parser, arguments);
|
||||
application.run();
|
||||
|
||||
let total_count_of_origins = get_origins_count(&settings.database.get_connection());
|
||||
|
@ -78,6 +84,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
|
|||
#[serial]
|
||||
fn should_route_to_origin(context: &FunctionalTestContext) {
|
||||
let parser = ArgumentParser {};
|
||||
let console = Console {};
|
||||
let settings = Settings::new().unwrap();
|
||||
let arguments = vec![
|
||||
String::from("release_checker"),
|
||||
|
@ -87,6 +94,6 @@ fn should_route_to_origin(context: &FunctionalTestContext) {
|
|||
String::from("name"),
|
||||
String::from("https://url"),
|
||||
];
|
||||
let application = Application::new(&settings, parser, arguments);
|
||||
let application = Application::new(&settings, &console, parser, arguments);
|
||||
application.run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue