Skip to content

Commit eb2f9fb

Browse files
committed
add test for list_hash_seq
1 parent aaa0101 commit eb2f9fb

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/rpc/client/tags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ where
270270
self.delete_with_opts(DeleteOptions::range(range)).await
271271
}
272272

273-
/// Lists all tags with the given prefix.
273+
/// Delete all tags with the given prefix.
274274
pub async fn delete_prefix(&self, prefix: impl AsRef<[u8]>) -> Result<()> {
275275
self.delete_with_opts(DeleteOptions::prefix(prefix.as_ref()))
276276
.await

tests/tags.rs

+29-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use iroh_blobs::{
88
client::tags::{self, TagInfo},
99
proto::RpcService,
1010
},
11-
BlobFormat, Hash,
11+
BlobFormat, Hash, HashAndFormat,
1212
};
1313
use testresult::TestResult;
1414

@@ -27,12 +27,18 @@ fn expected(tags: impl IntoIterator<Item = &'static str>) -> Vec<TagInfo> {
2727
.collect()
2828
}
2929

30+
async fn set<C: quic_rpc::Connector<RpcService>>(
31+
tags: &tags::Client<C>,
32+
names: impl IntoIterator<Item = &str>,
33+
) -> TestResult<()> {
34+
for name in names {
35+
tags.set(name, Hash::new(name)).await?;
36+
}
37+
Ok(())
38+
}
39+
3040
async fn tags_smoke<C: quic_rpc::Connector<RpcService>>(tags: tags::Client<C>) -> TestResult<()> {
31-
tags.set("a", Hash::new("a")).await?;
32-
tags.set("b", Hash::new("b")).await?;
33-
tags.set("c", Hash::new("c")).await?;
34-
tags.set("d", Hash::new("d")).await?;
35-
tags.set("e", Hash::new("e")).await?;
41+
set(&tags, ["a", "b", "c", "d", "e"]).await?;
3642
let stream = tags.list().await?;
3743
let res = to_vec(stream).await?;
3844
assert_eq!(res, expected(["a", "b", "c", "d", "e"]));
@@ -63,11 +69,7 @@ async fn tags_smoke<C: quic_rpc::Connector<RpcService>>(tags: tags::Client<C>) -
6369
let res = to_vec(stream).await?;
6470
assert_eq!(res, expected([]));
6571

66-
tags.set("a", Hash::new("a")).await?;
67-
tags.set("aa", Hash::new("aa")).await?;
68-
tags.set("aaa", Hash::new("aaa")).await?;
69-
tags.set("aab", Hash::new("aab")).await?;
70-
tags.set("b", Hash::new("b")).await?;
72+
set(&tags, ["a", "aa", "aaa", "aab", "b"]).await?;
7173

7274
let stream = tags.list_prefix("aa").await?;
7375
let res = to_vec(stream).await?;
@@ -83,9 +85,7 @@ async fn tags_smoke<C: quic_rpc::Connector<RpcService>>(tags: tags::Client<C>) -
8385
let res = to_vec(stream).await?;
8486
assert_eq!(res, expected([]));
8587

86-
tags.set("a", Hash::new("a")).await?;
87-
tags.set("b", Hash::new("b")).await?;
88-
tags.set("c", Hash::new("c")).await?;
88+
set(&tags, ["a", "b", "c"]).await?;
8989

9090
assert_eq!(
9191
tags.get("b").await?,
@@ -103,6 +103,21 @@ async fn tags_smoke<C: quic_rpc::Connector<RpcService>>(tags: tags::Client<C>) -
103103

104104
assert_eq!(tags.get("b").await?, None);
105105

106+
tags.delete_prefix("").await?;
107+
108+
tags.set("a", HashAndFormat::hash_seq(Hash::new("a")))
109+
.await?;
110+
tags.set("b", HashAndFormat::raw(Hash::new("b"))).await?;
111+
let stream = tags.list_hash_seq().await?;
112+
let res = to_vec(stream).await?;
113+
assert_eq!(
114+
res,
115+
vec![TagInfo {
116+
name: "a".into(),
117+
hash: Hash::new("a"),
118+
format: BlobFormat::HashSeq,
119+
},]
120+
);
106121
Ok(())
107122
}
108123

0 commit comments

Comments
 (0)