Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #86

Merged
merged 2 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
name: Clippy
with:
token: ${{ github.token }}
args: --workspace -- -D warnings
args: --workspace --all-features --all-targets -- -D warnings

- name: Audit
run: cargo audit --ignore RUSTSEC-2020-0159 --ignore RUSTSEC-2020-0071 --ignore RUSTSEC-2022-0006
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tide-disco"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["John D. Corbett <[email protected]>"]
description = "Discoverability for Tide"
Expand All @@ -25,7 +25,7 @@ futures = "0.3.21"
futures-util = "0.3.8"
http = "0.2.7"
include_dir = "0.7"
jf-utils = { features = ["std"], git = "https://github.com/EspressoSystems/jellyfish.git", tag = "0.1.1" }
jf-utils = { features = ["std"], git = "https://github.com/EspressoSystems/jellyfish.git", tag = "0.1.2" }
lazy_static = "1.4.0"
libc = "0.2.126"
markdown = "0.3"
Expand All @@ -39,8 +39,8 @@ serde_json = "1.0"
shellexpand = "2.0"
signal-hook = "0.3.14"
snafu = { version = "0.7", features = ["backtraces"] }
strum = "0.20"
strum_macros = "0.20.1"
strum = "0.24"
strum_macros = "0.24"
surf = "2.3.2"
tagged-base64 = { git = "https://github.com/EspressoSystems/tagged-base64.git", tag = "0.2.1" }
tide = { version = "0.16.0", default-features = false }
Expand Down
43 changes: 35 additions & 8 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ use crate::{
};
use async_trait::async_trait;
use derive_more::From;
use futures::{
future::{BoxFuture, Future},
stream::BoxStream,
};
use futures::{future::BoxFuture, stream::BoxStream};
use maud::{html, PreEscaped};
use semver::Version;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
Expand Down Expand Up @@ -995,14 +992,13 @@ impl<State, Error> Api<State, Error> {
///
/// This overrides the existing handler. If `health_check` has not yet been called, the default
/// handler is one which simply returns `Health::default()`.
pub async fn with_health_check<H, F>(
pub fn with_health_check<H>(
&mut self,
handler: impl 'static + Send + Sync + Fn(&State) -> F,
handler: impl 'static + Send + Sync + Fn(&State) -> BoxFuture<H>,
) -> &mut Self
where
State: 'static + Send + Sync,
H: HealthCheck,
F: 'static + Send + Future<Output = H>,
H: 'static + HealthCheck,
{
self.health_check = Some(route::health_check_handler(handler));
self
Expand Down Expand Up @@ -1162,6 +1158,7 @@ where
mod test {
use crate::{
error::{Error, ServerError},
healthcheck::HealthStatus,
socket::Connection,
wait_for_server, App, StatusCode, Url, SERVER_STARTUP_RETRIES, SERVER_STARTUP_SLEEP_MS,
};
Expand Down Expand Up @@ -1428,4 +1425,34 @@ mod test {
}
check_stream_closed(conn).await;
}

#[async_std::test]
async fn test_custom_healthcheck() {
let mut app = App::<_, ServerError>::with_state(HealthStatus::Available);
let api_toml = toml! {
[meta]
FORMAT_VERSION = "0.1.0"

[route.dummy]
PATH = ["/dummy"]
};
{
let mut api = app.module::<ServerError>("mod", api_toml).unwrap();
api.with_health_check(|state| async move { *state }.boxed());
}
let port = pick_unused_port().unwrap();
let url: Url = format!("http://localhost:{}", port).parse().unwrap();
spawn(app.serve(format!("0.0.0.0:{}", port)));
wait_for_server(&url, SERVER_STARTUP_RETRIES, SERVER_STARTUP_SLEEP_MS).await;

let mut res = surf::get(format!("http://localhost:{}/mod/healthcheck", port))
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
assert_eq!(
res.body_json::<HealthStatus>().await.unwrap(),
HealthStatus::Available
);
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ use tagged_base64::TaggedBase64;
use tide::http::mime;
use toml::value::Value;
use tracing::{error, trace};
use url::Url;

pub mod api;
pub mod app;
Expand All @@ -272,6 +271,7 @@ pub use error::Error;
pub use method::Method;
pub use request::{RequestError, RequestParam, RequestParamType, RequestParamValue, RequestParams};
pub use tide::http::{self, StatusCode};
pub use url::Url;

pub type Html = maud::Markup;

Expand Down
4 changes: 2 additions & 2 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ mod test {
err => panic!("expecting MissingParam {{ nosuchparam }}, got {:?}", err),
};

assert_eq!(req.boolean_param("boolean").unwrap(), true);
assert!(req.boolean_param("boolean").unwrap());
match req.boolean_param("integer").unwrap_err() {
RequestError::IncorrectParamType { actual, expected }
if actual == RequestParamType::Integer && expected == RequestParamType::Boolean => {
Expand Down Expand Up @@ -789,7 +789,7 @@ mod test {
None
);

assert_eq!(req.opt_boolean_param("boolean").unwrap().unwrap(), true);
assert!(req.opt_boolean_param("boolean").unwrap().unwrap());
match req.opt_boolean_param("integer").unwrap_err() {
RequestError::IncorrectParamType { actual, expected }
if actual == RequestParamType::Integer && expected == RequestParamType::Boolean => {
Expand Down
9 changes: 4 additions & 5 deletions src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use async_trait::async_trait;
use derive_more::From;
use futures::future::{BoxFuture, Future, FutureExt};
use futures::future::{BoxFuture, FutureExt};
use maud::{html, PreEscaped};
use serde::Serialize;
use snafu::{OptionExt, Snafu};
Expand Down Expand Up @@ -549,13 +549,12 @@ pub(crate) fn health_check_response<H: HealthCheck>(accept: &Accept, health: H)
///
/// Given a handler, this function can be used to derive a new, type-erased [HealthCheckHandler]
/// that takes only [RequestParams] and returns a generic [tide::Response].
pub(crate) fn health_check_handler<State, H, F>(
handler: impl 'static + Send + Sync + Fn(&State) -> F,
pub(crate) fn health_check_handler<State, H>(
handler: impl 'static + Send + Sync + Fn(&State) -> BoxFuture<H>,
) -> HealthCheckHandler<State>
where
State: 'static + Send + Sync,
H: HealthCheck,
F: 'static + Send + Future<Output = H>,
H: 'static + HealthCheck,
{
Box::new(move |req, state| {
let accept = req.accept().unwrap_or_else(|_| {
Expand Down