Skip to content

Commit

Permalink
fix(httpd): move the httpd test macro to the httpd crate
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <tareknaser360@gmail.com>
  • Loading branch information
tareknaser committed Jul 10, 2023
1 parent 5b4b3be commit 44d3b7e
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 26 deletions.
1 change: 1 addition & 0 deletions coffee_httpd/src/httpd.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod server;
pub use server::*;
pub mod macros;
15 changes: 15 additions & 0 deletions coffee_httpd/src/httpd/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// handle_httpd_response macro is the macro that handles HTTPD responses
#[macro_export]
macro_rules! handle_httpd_response {
($result:expr, $msg:expr) => {
match $result {
Ok(_) => Ok(HttpResponse::Ok().body(format!($msg))),
Err(err) => Err(actix_web::error::ErrorInternalServerError(format!(
"Error: {}",
err
))),
}
};
}

pub use handle_httpd_response;
2 changes: 1 addition & 1 deletion coffee_httpd/src/httpd/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::sync::Arc;
use serde_json::Value;
use tokio::sync::Mutex;

use super::macros::handle_httpd_response;
use coffee_core::coffee::CoffeeManager;
use coffee_lib::macros::handle_httpd_response;
use coffee_lib::plugin_manager::PluginManager;
use coffee_lib::types::request::*;

Expand Down
4 changes: 3 additions & 1 deletion coffee_httpd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ async fn main() {
println!("{err}");
}
let mut coffee = coffee.unwrap();
coffee.setup(&cmd.cln_path).await.unwrap();
if let Err(err) = coffee.setup(&cmd.cln_path).await {
println!("{err}");
}

let port = cmd.port.unwrap_or(8080) as u16;
log::info!("Running on port 127.0.0.1:{port}");
Expand Down
3 changes: 3 additions & 0 deletions coffee_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ log = "0.4.17"
env_logger = "0.9.3"
tokio = { version = "1.22.0", features = ["process"] }
paperclip = { version = "0.8.0", features = ["actix4"] }

[features]
httpd = ["paperclip/actix4"]
16 changes: 1 addition & 15 deletions coffee_lib/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,4 @@ macro_rules! sh {
};
}

/// handle_httpd_response macro is the macro that handles HTTPD responses
#[macro_export]
macro_rules! handle_httpd_response {
($result:expr, $msg:expr) => {
match $result {
Ok(_) => Ok(HttpResponse::Ok().body(format!($msg))),
Err(err) => Err(actix_web::error::ErrorInternalServerError(format!(
"Error: {}",
err
))),
}
};
}

pub use {error, handle_httpd_response, sh};
pub use {error, sh};
5 changes: 0 additions & 5 deletions coffee_lib/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ pub mod request {
use paperclip::actix::Apiv2Schema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Apiv2Schema, Serialize)]
pub struct Setup {
pub cln_dir: String,
}

#[derive(Debug, Deserialize, Apiv2Schema, Serialize)]
pub struct Install {
pub plugin: String,
Expand Down
10 changes: 7 additions & 3 deletions coffee_testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub mod macros {

#[macro_export]
macro_rules! httpd {
($dir:expr, $port:expr, $cln_path:expr, $($opt_args:tt)*) => {
($dir:expr, $port:expr, $($opt_args:tt)*) => {
async {
use tokio::process::Command;

Expand All @@ -57,7 +57,6 @@ pub mod macros {
.args(&args_tok)
.arg("--host=127.0.0.1")
.arg(format!("--port={}", $port))
.arg(format!("--cln-path={}", $cln_path))
.arg(format!("--data-dir={}", $dir.path().to_str().unwrap()))
.spawn()
}.await
Expand Down Expand Up @@ -177,7 +176,12 @@ impl CoffeeHTTPDTesting {
pub async fn tmp(cln_path: String) -> anyhow::Result<Self> {
let dir = tempfile::tempdir()?;
let port = port::random_free_port().unwrap();
let child = httpd!(dir, port, cln_path, "{}", format!("--network=regtest"))?;
let child = httpd!(
dir,
port,
"{}",
format!("--network=regtest --cln-path={cln_path}")
)?;
wait_for!(async { reqwest::get(format!("http://127.0.0.1:{}/list", port)).await });
Ok(Self {
root_path: Arc::new(dir),
Expand Down
2 changes: 1 addition & 1 deletion tests/src/coffee_httpd_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use coffee_testing::CoffeeHTTPDTesting;
use crate::init;

#[tokio::test(flavor = "multi_thread")]
// #[ntest::timeout(560000)]
#[ntest::timeout(560000)]
pub async fn httpd_init_add_remote() {
init();

Expand Down

0 comments on commit 44d3b7e

Please sign in to comment.