Skip to content

Commit bee5bfa

Browse files
committed
add a test for rename
1 parent 50ce9f7 commit bee5bfa

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

src/rpc/client/tags.rs

+20
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ where
289289
self.delete_with_opts(DeleteOptions::prefix(prefix.as_ref()))
290290
.await
291291
}
292+
293+
/// Delete all tags. Use with care. After this, all data will be garbage collected.
294+
pub async fn delete_all(&self) -> Result<()> {
295+
self.delete_with_opts(DeleteOptions {
296+
from: None,
297+
to: None,
298+
})
299+
.await
300+
}
292301
}
293302

294303
/// Information about a tag.
@@ -303,6 +312,17 @@ pub struct TagInfo {
303312
}
304313

305314
impl TagInfo {
315+
/// Create a new tag info.
316+
pub fn new(name: impl AsRef<[u8]>, value: impl Into<HashAndFormat>) -> Self {
317+
let name = name.as_ref();
318+
let value = value.into();
319+
Self {
320+
name: Tag::from(name),
321+
hash: value.hash,
322+
format: value.format,
323+
}
324+
}
325+
306326
/// Get the hash and format of the tag.
307327
pub fn hash_and_format(&self) -> HashAndFormat {
308328
HashAndFormat {

tests/tags.rs

+23-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, HashAndFormat,
11+
Hash, HashAndFormat,
1212
};
1313
use testresult::TestResult;
1414

@@ -19,11 +19,7 @@ async fn to_vec<T>(stream: impl Stream<Item = anyhow::Result<T>>) -> anyhow::Res
1919

2020
fn expected(tags: impl IntoIterator<Item = &'static str>) -> Vec<TagInfo> {
2121
tags.into_iter()
22-
.map(|tag| TagInfo {
23-
name: tag.into(),
24-
hash: Hash::new(tag),
25-
format: BlobFormat::Raw,
26-
})
22+
.map(|tag| TagInfo::new(tag, Hash::new(tag)))
2723
.collect()
2824
}
2925

@@ -89,11 +85,7 @@ async fn tags_smoke<C: quic_rpc::Connector<RpcService>>(tags: tags::Client<C>) -
8985

9086
assert_eq!(
9187
tags.get("b").await?,
92-
Some(TagInfo {
93-
name: "b".into(),
94-
hash: Hash::new("b"),
95-
format: BlobFormat::Raw,
96-
})
88+
Some(TagInfo::new("b", Hash::new("b")))
9789
);
9890

9991
tags.delete("b").await?;
@@ -103,7 +95,7 @@ async fn tags_smoke<C: quic_rpc::Connector<RpcService>>(tags: tags::Client<C>) -
10395

10496
assert_eq!(tags.get("b").await?, None);
10597

106-
tags.delete_prefix("").await?;
98+
tags.delete_all().await?;
10799

108100
tags.set("a", HashAndFormat::hash_seq(Hash::new("a")))
109101
.await?;
@@ -115,9 +107,26 @@ async fn tags_smoke<C: quic_rpc::Connector<RpcService>>(tags: tags::Client<C>) -
115107
vec![TagInfo {
116108
name: "a".into(),
117109
hash: Hash::new("a"),
118-
format: BlobFormat::HashSeq,
119-
},]
110+
format: iroh_blobs::BlobFormat::HashSeq,
111+
}]
120112
);
113+
114+
tags.delete_all().await?;
115+
set(&tags, ["c"]).await?;
116+
tags.rename("c", "f").await?;
117+
let stream = tags.list().await?;
118+
let res = to_vec(stream).await?;
119+
assert_eq!(
120+
res,
121+
vec![TagInfo {
122+
name: "f".into(),
123+
hash: Hash::new("c"),
124+
format: iroh_blobs::BlobFormat::Raw,
125+
}]
126+
);
127+
128+
let res = tags.rename("y", "z").await;
129+
assert!(res.is_err());
121130
Ok(())
122131
}
123132

0 commit comments

Comments
 (0)