Added contact to test
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Martin Slot 2022-12-07 17:08:44 +01:00
parent dbb63f269e
commit c4b9a9470f
6 changed files with 93 additions and 14 deletions

View File

@ -17,7 +17,7 @@ CREATE TABLE IF NOT EXISTS Currents
name NVARCHAR(50),
version NVARCHAR(50),
vcs_type NVARCHAR(20),
contact NVARCHAR(120),
contact NVARCHAR(120),
PRIMARY KEY (name, vcs_type),
FOREIGN KEY (name, vcs_type) REFERENCES Origins (name, vcs_type),
FOREIGN KEY (vcs_type) REFERENCES VcsTypes (vcs_type)

View File

@ -59,11 +59,17 @@ pub fn get_origins_count(connection: &Connection) -> usize {
count
}
pub fn insert_current(name: String, version: String, vcs_type: String, connection: &Connection) {
pub fn insert_current(
name: String,
version: String,
vcs_type: String,
email: String,
connection: &Connection,
) {
connection
.execute(
"INSERT INTO Currents (name, version, vcs_type) VALUES(?1, ?2, ?3)",
[&name, &version, &vcs_type],
"INSERT INTO Currents (name, version, vcs_type, contact) VALUES(?1, ?2, ?3, ?4)",
[&name, &version, &vcs_type, &email],
)
.unwrap();
}
@ -117,6 +123,27 @@ pub mod database {
}
}
pub mod notification {
use application::request::models::Current;
use application::request::notification::Notification;
pub struct FakeNotification<T>
where
T: Fn(),
{
pub callback: T,
}
impl<T> Notification for FakeNotification<T>
where
T: Fn(),
{
fn send(&self, currents: &Vec<Current>) {
(self.callback)();
}
}
}
pub mod console {
use application::console::Print;

View File

@ -4,6 +4,7 @@ use serial_test::serial;
use std::cell::Cell;
use test_context::test_context;
use test_utilities::console::FakeConsole;
use test_utilities::notification::FakeNotification;
use test_utilities::{
database::FunctionalTestContext, get_current, get_current_count, get_origin, get_origins_count,
insert_current, insert_origin,
@ -63,6 +64,8 @@ fn should_print_current(context: &FunctionalTestContext) {
);
let times_print_is_called = Cell::new(0);
let fake_notification = FakeNotification { callback: || {} };
let fake_console = FakeConsole {
callback: || {
let mut called = times_print_is_called.get();
@ -70,7 +73,13 @@ fn should_print_current(context: &FunctionalTestContext) {
times_print_is_called.set(called);
},
};
let application = Application::new(&context.settings, &fake_console, parser, arguments);
let application = Application::new(
&context.settings,
&fake_console,
&fake_notification,
parser,
arguments,
);
application.run();
assert_eq!(3, times_print_is_called.get());

View File

@ -4,6 +4,7 @@ use test_context::test_context;
use application::configuration::{ArgumentParser, Settings, VcsType};
use application::console::Console;
use application::{migrate, Application};
use test_utilities::notification::FakeNotification;
use test_utilities::{
database::FunctionalTestContext, get_current, get_current_count, get_origin, get_origins_count,
insert_origin,
@ -15,6 +16,7 @@ use test_utilities::{
fn shoud_save_only_one_current(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let arguments = vec![
String::from("release_checker"),
String::from("register"),
@ -32,7 +34,13 @@ fn shoud_save_only_one_current(context: &FunctionalTestContext) {
&context.settings.database.get_connection(),
);
let application = Application::new(&context.settings, &console, parser, arguments);
let application = Application::new(
&context.settings,
&console,
&fake_notification,
parser,
arguments,
);
application.run();
application.run();
@ -46,6 +54,7 @@ fn shoud_save_only_one_current(context: &FunctionalTestContext) {
fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let arguments = vec![
String::from("release_checker"),
String::from("register"),
@ -63,7 +72,13 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
&context.settings.database.get_connection(),
);
let application = Application::new(&context.settings, &console, parser, arguments);
let application = Application::new(
&context.settings,
&console,
&fake_notification,
parser,
arguments,
);
application.run();
let total_count_of_currents = get_origins_count(&context.settings.database.get_connection());
@ -80,6 +95,8 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let settings = Settings::new(None).unwrap();
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let arguments = vec![
String::from("release_checker"),
String::from("register"),
@ -88,7 +105,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
String::from("name"),
String::from("2"),
];
let application = Application::new(&settings, &console, parser, arguments);
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
application.run();
let total_count_of_currents = get_origins_count(&settings.database.get_connection());
@ -106,6 +123,8 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
fn should_route_to_current(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let arguments = vec![
String::from("release_checker"),
String::from("register"),
@ -114,6 +133,12 @@ fn should_route_to_current(context: &FunctionalTestContext) {
String::from("name"),
String::from("1"),
];
let application = Application::new(&context.settings, &console, parser, arguments);
let application = Application::new(
&context.settings,
&console,
&fake_notification,
parser,
arguments,
);
application.run();
}

View File

@ -4,6 +4,7 @@ use test_context::test_context;
use application::configuration::{ArgumentParser, Settings, VcsType};
use application::console::Console;
use application::Application;
use test_utilities::notification::FakeNotification;
use test_utilities::{database::FunctionalTestContext, get_origin, get_origins_count};
#[test_context(FunctionalTestContext)]
@ -12,6 +13,8 @@ use test_utilities::{database::FunctionalTestContext, get_origin, get_origins_co
fn shoud_save_only_one_origin(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
@ -22,7 +25,7 @@ fn shoud_save_only_one_origin(context: &FunctionalTestContext) {
String::from("owner_name"),
String::from("repo_name"),
];
let application = Application::new(&settings, &console, parser, arguments);
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
application.run();
application.run();
@ -36,6 +39,8 @@ fn shoud_save_only_one_origin(context: &FunctionalTestContext) {
fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
@ -46,7 +51,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
String::from("owner_name"),
String::from("repo_name"),
];
let application = Application::new(&settings, &console, parser, arguments);
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
let console = Console {};
let console = Console {};
application.run();
@ -62,6 +67,8 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
@ -72,7 +79,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
String::from("owner_name_updated"),
String::from("repo_name_updated"),
];
let application = Application::new(&settings, &console, parser, arguments);
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
application.run();
let total_count_of_origins = get_origins_count(&settings.database.get_connection());
@ -91,6 +98,8 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
fn should_route_to_origin(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
@ -101,6 +110,6 @@ fn should_route_to_origin(context: &FunctionalTestContext) {
String::from("owner_name"),
String::from("repo_name"),
];
let application = Application::new(&settings, &console, parser, arguments);
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
application.run();
}

View File

@ -6,6 +6,7 @@ use application::configuration::ArgumentParser;
use application::Application;
use test_utilities::console::FakeConsole;
use test_utilities::database::FunctionalTestContext;
use test_utilities::notification::FakeNotification;
use test_utilities::{insert_current, insert_origin};
#[test_context(FunctionalTestContext)]
@ -27,10 +28,12 @@ fn should_make_request(context: &FunctionalTestContext) {
String::from("name1"),
"1".to_string(),
"github".to_string(),
"email@domain.tld".to_string(),
&context.settings.database.get_connection(),
);
let fake_console = FakeConsole { callback: || {} };
let fake_notification = FakeNotification { callback: || {} };
// Create a mock on the server.
let releases_mock = context.mock_server.mock(|when, then| {
@ -41,7 +44,13 @@ fn should_make_request(context: &FunctionalTestContext) {
.body("{\"tag_name\":\"tag_name\",\"name\":\"name\"}"); // TODO: this a really simple return that just returns what i want. It should contain the full json blob that /releases returns
});
let application = Application::new(&context.settings, &fake_console, parser, arguments);
let application = Application::new(
&context.settings,
&fake_console,
&fake_notification,
parser,
arguments,
);
application.run();