Skip to content

Commit

Permalink
add deprecation note to fields and remove remaining use in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Jun 7, 2024
1 parent 7ea851a commit e9f0350
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
25 changes: 17 additions & 8 deletions iroh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ mod node;
#[derive(Debug, Clone)]
pub struct Iroh<C> {
/// Client for blobs operations.
blobs: blobs::Client<C>,
#[deprecated(note = "Use `blobs` method instead", since = "0.18.0")]
pub blobs: blobs::Client<C>,
/// Client for docs operations.
docs: docs::Client<C>,
#[deprecated(note = "Use `docs` method instead", since = "0.18.0")]
pub docs: docs::Client<C>,
/// Client for author operations.
authors: authors::Client<C>,
#[deprecated(note = "Use `authors` method instead", since = "0.18.0")]
pub authors: authors::Client<C>,
/// Client for tags operations.
tags: tags::Client<C>,
#[deprecated(note = "Use `tags` method instead", since = "0.18.0")]
pub tags: tags::Client<C>,

rpc: RpcClient<RpcService, C>,
}
Expand All @@ -43,6 +47,7 @@ where
{
/// Create a new high-level client to a Iroh node from the low-level RPC client.
pub fn new(rpc: RpcClient<RpcService, C>) -> Self {
#[allow(deprecated)]
Self {
blobs: blobs::Client { rpc: rpc.clone() },
docs: docs::Client { rpc: rpc.clone() },
Expand All @@ -52,23 +57,27 @@ where
}
}

///
/// Client for blobs operations.
pub fn blobs(&self) -> &blobs::Client<C> {
#[allow(deprecated)]
&self.blobs
}

///
/// Client for docs operations.
pub fn docs(&self) -> &docs::Client<C> {
#[allow(deprecated)]
&self.docs
}

///
/// Client for author operations.
pub fn authors(&self) -> &authors::Client<C> {
#[allow(deprecated)]
&self.authors
}

///
/// Client for tags operations.
pub fn tags(&self) -> &tags::Client<C> {
#[allow(deprecated)]
&self.tags
}
}
Expand Down
24 changes: 12 additions & 12 deletions iroh/src/client/authors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,33 @@ mod tests {
let node = Node::memory().spawn().await?;

// default author always exists
let authors: Vec<_> = node.authors.list().await?.try_collect().await?;
let authors: Vec<_> = node.authors().list().await?.try_collect().await?;
assert_eq!(authors.len(), 1);
let default_author = node.authors.default().await?;
let default_author = node.authors().default().await?;
assert_eq!(authors, vec![default_author]);

let author_id = node.authors.create().await?;
let author_id = node.authors().create().await?;

let authors: Vec<_> = node.authors.list().await?.try_collect().await?;
let authors: Vec<_> = node.authors().list().await?.try_collect().await?;
assert_eq!(authors.len(), 2);

let author = node
.authors
.authors()
.export(author_id)
.await?
.expect("should have author");
node.authors.delete(author_id).await?;
let authors: Vec<_> = node.authors.list().await?.try_collect().await?;
node.authors().delete(author_id).await?;
let authors: Vec<_> = node.authors().list().await?.try_collect().await?;
assert_eq!(authors.len(), 1);

node.authors.import(author).await?;
node.authors().import(author).await?;

let authors: Vec<_> = node.authors.list().await?.try_collect().await?;
let authors: Vec<_> = node.authors().list().await?.try_collect().await?;
assert_eq!(authors.len(), 2);

assert!(node.authors.default().await? != author_id);
node.authors.set_default(author_id).await?;
assert_eq!(node.authors.default().await?, author_id);
assert!(node.authors().default().await? != author_id);
node.authors().set_default(author_id).await?;
assert_eq!(node.authors().default().await?, author_id);

Ok(())
}
Expand Down
24 changes: 12 additions & 12 deletions iroh/src/client/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ mod tests {
// import files
for path in &paths {
let import_outcome = client
.blobs
.blobs()
.add_from_path(
path.to_path_buf(),
false,
Expand All @@ -957,7 +957,7 @@ mod tests {
}

let (hash, tag) = client
.blobs
.blobs()
.create_collection(collection, SetTagOption::Auto, tags)
.await?;

Expand All @@ -978,7 +978,7 @@ mod tests {
}

// check that "temp" tags have been deleted
let tags: Vec<_> = client.tags.list().await?.try_collect().await?;
let tags: Vec<_> = client.tags().list().await?.try_collect().await?;
assert_eq!(tags.len(), 1);
assert_eq!(tags[0].hash, hash);
assert_eq!(tags[0].name, tag);
Expand Down Expand Up @@ -1013,7 +1013,7 @@ mod tests {
let client = node.client();

let import_outcome = client
.blobs
.blobs()
.add_from_path(
path.to_path_buf(),
false,
Expand Down Expand Up @@ -1043,29 +1043,29 @@ mod tests {

// Read at equal to blob_get_chunk_size
let res = client
.blobs
.blobs()
.read_at_to_bytes(hash, 0, Some(1024 * 64))
.await?;
assert_eq!(res.len(), 1024 * 64);
assert_eq!(&res[..], &buf[0..1024 * 64]);

let res = client
.blobs
.blobs()
.read_at_to_bytes(hash, 20, Some(1024 * 64))
.await?;
assert_eq!(res.len(), 1024 * 64);
assert_eq!(&res[..], &buf[20..(20 + 1024 * 64)]);

// Read at larger than blob_get_chunk_size
let res = client
.blobs
.blobs()
.read_at_to_bytes(hash, 0, Some(10 + 1024 * 64))
.await?;
assert_eq!(res.len(), 10 + 1024 * 64);
assert_eq!(&res[..], &buf[0..(10 + 1024 * 64)]);

let res = client
.blobs
.blobs()
.read_at_to_bytes(hash, 20, Some(10 + 1024 * 64))
.await?;
assert_eq!(res.len(), 10 + 1024 * 64);
Expand Down Expand Up @@ -1119,7 +1119,7 @@ mod tests {
// import files
for path in &paths {
let import_outcome = client
.blobs
.blobs()
.add_from_path(
path.to_path_buf(),
false,
Expand All @@ -1140,7 +1140,7 @@ mod tests {
}

let (hash, _tag) = client
.blobs
.blobs()
.create_collection(collection, SetTagOption::Auto, tags)
.await?;

Expand Down Expand Up @@ -1178,7 +1178,7 @@ mod tests {
let client = node.client();

let import_outcome = client
.blobs
.blobs()
.add_from_path(
path.to_path_buf(),
false,
Expand All @@ -1192,7 +1192,7 @@ mod tests {
.context("import finish")?;

let ticket = client
.blobs
.blobs()
.share(import_outcome.hash, BlobFormat::Raw, Default::default())
.await?;
assert_eq!(ticket.hash(), import_outcome.hash);
Expand Down

0 comments on commit e9f0350

Please sign in to comment.