Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bgins committed Nov 2, 2023
1 parent 533d72f commit f524b11
Showing 1 changed file with 16 additions and 44 deletions.
60 changes: 16 additions & 44 deletions homestar-runtime/src/tasks/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const WASM_CID: &str = "bafkreihxcyjgyrz437ewzi7md55uqt2zf6yr3zn7xrfi4orc34xdc5j

impl Fetch {
/// Gather resources from IPFS or elsewhere, leveraging an exponential backoff.
#[cfg(feature = "ipfs")]
#[cfg(all(feature = "ipfs", not(test)))]
#[cfg_attr(docsrs, doc(cfg(feature = "ipfs")))]
pub(crate) async fn get_resources(
resources: FnvHashSet<Resource>,
Expand All @@ -34,53 +34,16 @@ impl Fetch {
tasks.push(task);
}

#[cfg(not(test))]
let res = tasks.try_collect::<Vec<_>>().await?.into_iter().try_fold(
tasks.try_collect::<Vec<_>>().await?.into_iter().try_fold(
IndexMap::default(),
|mut acc, res| {
println!("NOT TEST");
let answer = res.1?;
acc.insert(res.0, answer);

Ok::<_, anyhow::Error>(acc)
},
);

#[cfg(test)]
let bytes = Self::_get_resources().await?;

#[cfg(test)]
if tasks.is_empty() {
let mut map = IndexMap::default();
map.insert(
Resource::Url(url::Url::parse(format!("ipfs://{WASM_CID}").as_str()).unwrap()),
bytes,
);
return Ok(map);
}

println!("HERE?");

#[cfg(test)]
let res = tasks.try_collect::<Vec<_>>().await?.into_iter().try_fold(
IndexMap::default(),
|mut acc, res| {
println!("FUDGE");
if let Ok(bytes) = res.1 {
acc.insert(res.0, bytes);
} else {
println!("Using test bytes");
acc.insert(
Resource::Url(url::Url::parse(format!("ipfs://{WASM_CID}").as_str())?),
bytes.clone(),
);
}
Ok::<_, anyhow::Error>(acc)
},
);

println!("res: {:?}", res);

res
)
}

/// Gather resources via URLs, leveraging an exponential backoff.
Expand Down Expand Up @@ -119,18 +82,27 @@ impl Fetch {
#[cfg(all(feature = "ipfs", test))]
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) async fn _get_resources() -> Result<Vec<u8>> {
pub(crate) async fn get_resources(
_resources: FnvHashSet<Resource>,
_settings: Arc<workflow::Settings>,
_ipfs: IpfsCli,
) -> Result<IndexMap<Resource, Vec<u8>>> {
println!("Running in test mode");
use crate::tasks::FileLoad;
let path = std::path::PathBuf::from(format!(
"{}/../homestar-wasm/fixtures/example_add.wasm",
env!("CARGO_MANIFEST_DIR")
));
let bytes = crate::tasks::WasmContext::load(path).await.unwrap();
Ok(bytes)
let mut map = IndexMap::default();
map.insert(
Resource::Url(url::Url::parse(format!("ipfs://{WASM_CID}").as_str()).unwrap()),
bytes,
);
Ok(map)
}

#[cfg(feature = "ipfs")]
#[cfg(all(feature = "ipfs", not(test)))]
async fn fetch(rsc: Resource, client: IpfsCli) -> Result<(Resource, Result<Vec<u8>>)> {
match rsc {
Resource::Url(url) => {
Expand Down

0 comments on commit f524b11

Please sign in to comment.