use crate::test::*;
use anyhow::{Context, Result};
use commandspec::{sh_command, sh_execute};
-use tokio::runtime::Runtime;
use with_procspawn_tempdir::with_procspawn_tempdir;
#[itest]
Ok(())
}
-async fn impl_test_pull_basicauth() -> Result<()> {
+#[itest]
+#[with_procspawn_tempdir]
+fn test_pull_basicauth() -> Result<()> {
let opts = TestHttpServerOpts {
basicauth: true,
..Default::default()
};
let serverrepo = Path::new("server/repo");
std::fs::create_dir_all(&serverrepo)?;
- let addr = http_server(&serverrepo, opts).await?;
- tokio::task::spawn_blocking(move || -> Result<()> {
+ with_webserver_in(&serverrepo, &opts, move |addr| {
let baseuri = http::Uri::from_maybe_shared(format!("http://{}/", addr).into_bytes())?;
let unauthuri =
http::Uri::from_maybe_shared(format!("http://unknown:badpw@{}/", addr).into_bytes())?;
}
sh_execute!(r#"ostree --repo=client/repo pull origin-goodauth os >/dev/null"#,)?;
Ok(())
- })
- .await??;
- Ok(())
-}
-
-#[itest]
-#[with_procspawn_tempdir]
-fn test_pull_basicauth() -> Result<()> {
- let mut rt = Runtime::new()?;
- rt.block_on(async move { impl_test_pull_basicauth().await })?;
+ })?;
Ok(())
}
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response};
use hyper_staticfile::Static;
+use tokio::runtime::Runtime;
pub(crate) type TestFn = fn() -> Result<()>;
Ok(addr)
}
+pub(crate) fn with_webserver_in<P: AsRef<Path>, F>(
+ path: P,
+ opts: &TestHttpServerOpts,
+ f: F) -> Result<()>
+where
+ F: FnOnce(&std::net::SocketAddr) -> Result<()>,
+ F: Send + 'static,
+{
+ let path = path.as_ref();
+ let mut rt = Runtime::new()?;
+ rt.block_on(async move {
+ let addr = http_server(path, opts.clone()).await?;
+ tokio::task::spawn_blocking(move || f(&addr)).await?
+ })?;
+ Ok(())
+}
+
// I put tests in your tests so you can test while you test
#[cfg(test)]
mod tests {