directory: healthcheck requester now returns a Response<>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use reqwest::Response;
|
||||
|
||||
pub struct Requester {
|
||||
base_url: String
|
||||
}
|
||||
|
||||
pub trait HealthCheckRequester {
|
||||
fn new(base_url: String) -> Self;
|
||||
fn get(&self) -> bool;
|
||||
fn get(&self) -> Result<Response, reqwest::Error>;
|
||||
}
|
||||
|
||||
impl HealthCheckRequester for Requester {
|
||||
@@ -14,18 +16,9 @@ impl HealthCheckRequester for Requester {
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&self) -> bool {
|
||||
fn get(&self) -> Result<Response, reqwest::Error> {
|
||||
let url = format!("{}/healthcheck", self.base_url);
|
||||
match reqwest::get(&url) {
|
||||
Ok(response) => {
|
||||
if response.status() == 200 {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
Err(e) => false,
|
||||
}
|
||||
reqwest::get(&url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,30 +33,28 @@ mod healthcheck_requests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_returns_false() {
|
||||
#[should_panic]
|
||||
fn it_returns_an_error() {
|
||||
let _m = mock("GET", "/healthcheck")
|
||||
.with_status(400)
|
||||
.create();
|
||||
let req = Requester::new(mockito::server_url());
|
||||
|
||||
let expected = false;
|
||||
assert_eq!(expected, req.get());
|
||||
assert_eq!(true, req.get().is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod on_a_200_with_ok_json {
|
||||
mod on_a_200 {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_returns_true() {
|
||||
fn it_returns_a_response_with_200_status() {
|
||||
let _m = mock("GET", "/healthcheck")
|
||||
.with_status(200)
|
||||
.create();
|
||||
let req = Requester::new(mockito::server_url());
|
||||
|
||||
let expected = true;
|
||||
assert_eq!(expected, req.get());
|
||||
assert_eq!(true, req.get().is_ok());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,13 @@ pub struct Config {
|
||||
|
||||
pub trait DirectoryClient {
|
||||
fn new(config : Config) -> Self;
|
||||
fn health_check(&self) -> Result<bool, Error>;
|
||||
fn get_topology(&self) -> Result<Topology, reqwest::Error>;
|
||||
// fn send_provider_presence(&self) -> Result<ProviderPresenceResponse, reqwest::Error>;
|
||||
}
|
||||
|
||||
pub struct Client {
|
||||
health_check: Requester,
|
||||
pub health_check: Requester,
|
||||
}
|
||||
|
||||
impl DirectoryClient for Client {
|
||||
@@ -32,6 +33,14 @@ impl DirectoryClient for Client {
|
||||
}
|
||||
}
|
||||
|
||||
fn health_check(&self) -> Result<bool, Error> {
|
||||
unimplemented!()
|
||||
// match self.health_check.get() {
|
||||
// true => Ok(true),
|
||||
// false => Err("foo"),
|
||||
// }
|
||||
}
|
||||
|
||||
fn get_topology(&self) -> Result<Topology, Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user