Added some tests related to request
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
34e8b21c19
commit
0348df3c60
|
@ -66,7 +66,7 @@ impl ArgumentParser {
|
|||
// TODO: This should be rethought. Right now it covers all, but it is a pain to more VcsTypes possible
|
||||
match matches.subcommand() {
|
||||
Some(("list", sub_matches)) => Ok(Action::List),
|
||||
|
||||
Some(("request", sub_matches)) => Ok(Action::Request),
|
||||
Some(("register", sub_matches)) => match sub_matches.subcommand() {
|
||||
Some(("current", sub_matches)) => match sub_matches.subcommand() {
|
||||
Some(("github", sub_matches)) => {
|
||||
|
|
|
@ -34,7 +34,7 @@ impl<'a> CurrentGateway<'a> {
|
|||
pub fn upsert_current(&self, name: String, version: String, vcs_type: VcsType) {
|
||||
let connection = self.settings.database.get_connection();
|
||||
|
||||
//TODO: this should be wrapped somewhere else, because it is going to be used a lot of places. I think there must be some rustic way of doing this
|
||||
// TODO: this should be wrapped somewhere else, because it is going to be used a lot of places. I think there must be some rustic way of doing this
|
||||
let vcs_type = match vcs_type {
|
||||
VcsType::Github => String::from("github"),
|
||||
_ => String::from("Unknown"),
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use crate::configuration::VcsType;
|
||||
use crate::request::models::Current;
|
||||
use crate::{Print, Settings};
|
||||
|
||||
pub fn init<'a>(settings: &'a Settings, console: &'a dyn Print) -> RequestHandler<'a> {
|
||||
|
@ -20,11 +22,54 @@ pub struct RequestGateway<'a> {
|
|||
}
|
||||
|
||||
impl<'a> RequestHandler<'a> {
|
||||
pub fn execute(&self) {}
|
||||
pub fn execute(&self) {
|
||||
let currents = self.request_gateway.get_currents();
|
||||
// fetch release page from provider
|
||||
// convert to obj
|
||||
// compare
|
||||
// send alert
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RequestGateway<'a> {
|
||||
pub fn new(settings: &Settings) -> RequestGateway {
|
||||
RequestGateway { settings }
|
||||
}
|
||||
|
||||
pub fn get_currents(&self) -> Vec<Current> {
|
||||
let connection = self.settings.database.get_connection();
|
||||
let mut prepared = connection
|
||||
.prepare(
|
||||
"SELECT C.name, C.vcs_type, O.url\
|
||||
FROM Origins O\
|
||||
JOIN Crurrents C ON O.name = C.name AND O.vcs_type = C.vcs_type",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let iter = prepared
|
||||
.query_map([], |row| {
|
||||
let vcs: String = row.get(1).unwrap();
|
||||
Ok(Current {
|
||||
name: row.get(0).unwrap(),
|
||||
vcs_type: match vcs.as_str() {
|
||||
"github" => VcsType::Github,
|
||||
_ => VcsType::Unknown,
|
||||
},
|
||||
url: row.get(2).unwrap(),
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
iter.map(|x| x.unwrap()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod models {
|
||||
use crate::configuration::VcsType;
|
||||
|
||||
pub struct Current {
|
||||
pub name: String,
|
||||
pub vcs_type: VcsType,
|
||||
pub url: String,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
/* TODO: should the vcs_type only be on the Origins? And then have a primary key (forward key) on origins that currents can reference? */
|
||||
/*
|
||||
TODO: should the vcs_type only be on the Origins? And then have a primary key (forward key) on origins that currents can reference?
|
||||
*/
|
||||
CREATE TABLE IF NOT EXISTS Origins
|
||||
(
|
||||
name NVARCHAR(50),
|
||||
|
|
|
@ -27,3 +27,7 @@ path = "register_current_test.rs"
|
|||
[[test]]
|
||||
name = "list_overview_test"
|
||||
path = "list_overview_test.rs"
|
||||
|
||||
[[test]]
|
||||
name = "request_test"
|
||||
path = "request_test.rs"
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
use application::configuration::ArgumentParser;
|
||||
use application::Application;
|
||||
use serial_test::serial;
|
||||
use std::cell::Cell;
|
||||
use test_context::test_context;
|
||||
use test_utilities::console::FakeConsole;
|
||||
use test_utilities::database::FunctionalTestContext;
|
||||
use test_utilities::{insert_current, insert_origin};
|
||||
|
||||
#[test_context(FunctionalTestContext)]
|
||||
#[test]
|
||||
#[serial]
|
||||
fn should_make_request(context: &FunctionalTestContext) {
|
||||
let parser = ArgumentParser {};
|
||||
let arguments = vec![String::from("release_checker"), String::from("request")];
|
||||
|
||||
insert_origin(
|
||||
String::from("name1"),
|
||||
String::from("https://url"),
|
||||
String::from("github"),
|
||||
&context.settings.database.get_connection(),
|
||||
);
|
||||
|
||||
insert_current(
|
||||
String::from("name1"),
|
||||
"1".to_string(),
|
||||
"github".to_string(),
|
||||
&context.settings.database.get_connection(),
|
||||
);
|
||||
|
||||
insert_origin(
|
||||
String::from("name2"),
|
||||
String::from("https://url"),
|
||||
String::from("github"),
|
||||
&context.settings.database.get_connection(),
|
||||
);
|
||||
|
||||
insert_current(
|
||||
String::from("name2"),
|
||||
"1".to_string(),
|
||||
"github".to_string(),
|
||||
&context.settings.database.get_connection(),
|
||||
);
|
||||
|
||||
insert_origin(
|
||||
String::from("name3"),
|
||||
String::from("https://url"),
|
||||
String::from("github"),
|
||||
&context.settings.database.get_connection(),
|
||||
);
|
||||
|
||||
insert_current(
|
||||
String::from("name3"),
|
||||
"1".to_string(),
|
||||
"github".to_string(),
|
||||
&context.settings.database.get_connection(),
|
||||
);
|
||||
|
||||
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();
|
||||
}
|
Loading…
Reference in New Issue