Added notification send and test. It now works without v in the tag, from github
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Martin Slot 2022-12-08 20:44:26 +01:00
parent d6324dfd4d
commit fbdc947707
2 changed files with 74 additions and 3 deletions

View File

@ -67,7 +67,9 @@ impl<'a> RequestHandler<'a> {
}
}
// send alerts
if !send_alerts_for.is_empty() {
self.request_gateway.notification.send(&currents);
}
}
}

View File

@ -1,5 +1,6 @@
use httpmock::prelude::*;
use serial_test::serial;
use std::cell::Cell;
use test_context::test_context;
use application::configuration::ArgumentParser;
@ -12,7 +13,9 @@ use test_utilities::{insert_current, insert_origin};
#[test_context(FunctionalTestContext)]
#[test]
#[serial]
fn should_make_request_gets_version_without_v_from_github(context: &FunctionalTestContext) {
fn should_make_request_gets_version_without_v_from_github_equal_versions(
context: &FunctionalTestContext,
) {
let parser = ArgumentParser {};
let arguments = vec![String::from("release_checker"), String::from("request")];
@ -32,8 +35,15 @@ fn should_make_request_gets_version_without_v_from_github(context: &FunctionalTe
&context.settings.database.get_connection(),
);
let times_notification_is_called = Cell::new(0);
let fake_console = FakeConsole { callback: || {} };
let fake_notification = FakeNotification { callback: || {} };
let fake_notification = FakeNotification {
callback: || {
let mut called = times_notification_is_called.get();
called += 1;
times_notification_is_called.set(called);
},
};
// Create a mock on the server.
let releases_mock = context.mock_server.mock(|when, then| {
@ -55,4 +65,63 @@ fn should_make_request_gets_version_without_v_from_github(context: &FunctionalTe
application.run();
releases_mock.assert();
assert_eq!(0, times_notification_is_called.get());
}
#[test_context(FunctionalTestContext)]
#[test]
#[serial]
fn should_make_request_gets_version_without_v_from_github_current_is_smaller(
context: &FunctionalTestContext,
) {
let parser = ArgumentParser {};
let arguments = vec![String::from("release_checker"), String::from("request")];
insert_origin(
String::from("name1"),
String::from("owner_name"),
String::from("repo_name"),
String::from("github"),
&context.settings.database.get_connection(),
);
insert_current(
String::from("name1"),
"1.2.2".to_string(),
"github".to_string(),
"email@domain.tld".to_string(),
&context.settings.database.get_connection(),
);
let times_notification_is_called = Cell::new(0);
let fake_console = FakeConsole { callback: || {} };
let fake_notification = FakeNotification {
callback: || {
let mut called = times_notification_is_called.get();
called += 1;
times_notification_is_called.set(called);
},
};
// Create a mock on the server.
let releases_mock = context.mock_server.mock(|when, then| {
when.method(GET)
.path("/repos/owner_name/repo_name/releases/latest");
then.status(200)
.header("content-type", "application/json")
.body("{\"tag_name\":\"1.2.3\",\"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,
&fake_notification,
parser,
arguments,
);
application.run();
releases_mock.assert();
assert_eq!(1, times_notification_is_called.get());
}