From daf6edbab29d13ef8e2cd3f33a879fa7c2d415ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Kr=C3=BCger?= Date: Mon, 4 Mar 2024 11:09:50 +0100 Subject: [PATCH] chore: Run reqwest axum integration with coverage --- car-mirror-reqwest/Cargo.toml | 4 ++++ car-mirror-reqwest/tests/integration.rs | 31 +++++++++++++++++++++++++ car-mirror/src/dag_walk.rs | 4 ++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 car-mirror-reqwest/tests/integration.rs diff --git a/car-mirror-reqwest/Cargo.toml b/car-mirror-reqwest/Cargo.toml index bdf995d..6df20fa 100644 --- a/car-mirror-reqwest/Cargo.toml +++ b/car-mirror-reqwest/Cargo.toml @@ -49,3 +49,7 @@ wnfs-unixfs-file = { workspace = true } all-features = true # defines the configuration attribute `docsrs` rustdoc-args = ["--cfg", "docsrs"] + +[[test]] +name = "integration" +path = "tests/integration.rs" diff --git a/car-mirror-reqwest/tests/integration.rs b/car-mirror-reqwest/tests/integration.rs new file mode 100644 index 0000000..557116e --- /dev/null +++ b/car-mirror-reqwest/tests/integration.rs @@ -0,0 +1,31 @@ +//! A copy of the doctest in lib.rs, because code coverage is buggy +//! with doctests. +use car_mirror::{cache::NoCache, common::Config}; +use car_mirror_reqwest::RequestBuilderExt; +use reqwest::Client; +use testresult::TestResult; +use wnfs_common::{BlockStore, MemoryBlockStore, CODEC_RAW}; + +#[test_log::test(tokio::test)] +async fn test_car_mirror_reqwest_axum_integration() -> TestResult { + tokio::spawn(car_mirror_axum::serve(MemoryBlockStore::new())); + + let store = MemoryBlockStore::new(); + let data = b"Hello, world!".to_vec(); + let root = store.put_block(data, CODEC_RAW).await?; + + let client = Client::new(); + client + .post(format!("http://localhost:3344/dag/push/{root}")) + .run_car_mirror_push(root, &store, &NoCache) + .await?; + + let store = MemoryBlockStore::new(); // clear out data + client + .post(format!("http://localhost:3344/dag/pull/{root}")) + .run_car_mirror_pull(root, &Config::default(), &store, &NoCache) + .await?; + + assert!(store.has_block(&root).await?); + Ok(()) +} diff --git a/car-mirror/src/dag_walk.rs b/car-mirror/src/dag_walk.rs index 045d0ec..510afd9 100644 --- a/car-mirror/src/dag_walk.rs +++ b/car-mirror/src/dag_walk.rs @@ -270,12 +270,12 @@ mod proptests { use futures::TryStreamExt; use libipld::{ multihash::{Code, MultihashDigest}, - Cid, Ipld, IpldCodec, + Ipld, IpldCodec, }; use proptest::strategy::Strategy; use std::collections::BTreeSet; use test_strategy::proptest; - use wnfs_common::{encode, BlockStore, MemoryBlockStore}; + use wnfs_common::{encode, MemoryBlockStore}; fn ipld_dags() -> impl Strategy, Cid)> { arb_ipld_dag(1..256, 0.5, |cids, _| {