Fixed mockserver test ... I actually can test intgration to providers now! I wished i had a community to celebrate this with!!!
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Martin Slot 2022-11-14 16:36:17 +01:00
parent cdd0070d94
commit 86582576a4
8 changed files with 18 additions and 17 deletions

View File

@ -32,12 +32,12 @@ impl<'a> RequestHandler<'a> {
None => &current.api_root_url,
};
let releases_api_url = format!(
"{}/repos/{}/{}/releases", // api_root_url contains protocol - this is very much hard coded to Github right now, so i wont make any fancy factory or something. When there is added another provider i will think on how to do this the correct way
let latest_release_api_url = format!(
"{}repos/{}/{}/releases/latest", // api_root_url contains protocol - this is very much hard coded to Github right now, so i wont make any fancy factory or something. When there is added another provider i will think on how to do this the correct way
api_url, current.owner_name, current.repo_name
);
let release = reqwest::blocking::get(releases_api_url)
let release = reqwest::blocking::get(latest_release_api_url)
.unwrap()
.json::<GithubRelease>()
.unwrap();

View File

@ -36,7 +36,7 @@ where
repo_name,
vcsType,
} => (self.register_origin)(name, owner_name, repo_name, vcsType),
Action::Request => {}
Action::Request => (self.request)(),
Action::List => (self.list)(),
Action::RegisterCurrent {
name,

View File

@ -4,7 +4,7 @@ use application::Application;
fn main() {
let parser = ArgumentParser {};
let settings = Settings::new().unwrap();
let settings = Settings::new(None).unwrap();
let console = Console {};
let args = std::env::args().collect();
let application = Application::new(&settings, &console, parser, args);

View File

@ -100,7 +100,7 @@ pub mod database {
impl TestContext for FunctionalTestContext {
fn setup() -> Self {
let mock_server = MockServer::start(); // TODO: this could be overkill to start a server on every test but for now this is the easiests
let mock_server = MockServer::start(); // TODO: this could be overkill to start a server on every test but for now this is the most easy. It also will start a server on every functional test, and that kind of sets an upper bond on how many tests that can be created :D I need to look into this. Maybe just call .start when i need to?
let settings = Settings::new(Some(mock_server.url("/").as_str())).unwrap();
migrate(&settings);
FunctionalTestContext {

View File

@ -78,7 +78,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
assert_eq!(current.vcs_type, VcsType::Github);
let parser = ArgumentParser {};
let settings = Settings::new().unwrap();
let settings = Settings::new(None).unwrap();
let console = Console {};
let arguments = vec![
String::from("release_checker"),

View File

@ -1,8 +1,9 @@
use serial_test::serial;
use test_context::test_context;
use application::configuration::{ArgumentParser, Settings, VcsType};
use application::console::Console;
use application::Application;
use serial_test::serial;
use test_context::test_context;
use test_utilities::{database::FunctionalTestContext, get_origin, get_origins_count};
#[test_context(FunctionalTestContext)]
@ -11,7 +12,7 @@ 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 settings = Settings::new().unwrap();
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
String::from("register"),
@ -35,7 +36,7 @@ fn shoud_save_only_one_origin(context: &FunctionalTestContext) {
fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let settings = Settings::new().unwrap();
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
String::from("register"),
@ -61,7 +62,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let settings = Settings::new().unwrap();
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
String::from("register"),
@ -90,7 +91,7 @@ fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
fn should_route_to_origin(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let settings = Settings::new().unwrap();
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
String::from("register"),

View File

@ -35,10 +35,10 @@ fn should_make_request(context: &FunctionalTestContext) {
// 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");
.path("/repos/owner_name/repo_name/releases/latest");
then.status(200)
.header("content-type", "application/json")
.body("{}");
.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);

View File

@ -1,13 +1,13 @@
#[test]
fn can_default_settings_be_loaded() {
let settings =
application::configuration::Settings::new().expect("error when loading settings");
application::configuration::Settings::new(None).expect("error when loading settings");
}
#[test]
fn database_settings_can_be_loaded() {
let settings =
application::configuration::Settings::new().expect("error when loading settings");
application::configuration::Settings::new(None).expect("error when loading settings");
assert_eq!("version_checker_db", settings.database.connection_string);
assert!(!settings.database.in_memory);
}