mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
no panic on failed torrent_add
This commit is contained in:
parent
70b6b822c4
commit
4e932deb49
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "transmission-rpc"
|
name = "transmission-rpc"
|
||||||
version = "0.2.3"
|
version = "0.3.0"
|
||||||
authors = ["red <red.avtovo@gmail.com>"]
|
authors = ["red <red.avtovo@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
repository = "https://github.com/j0rsa/transmission-rpc"
|
repository = "https://github.com/j0rsa/transmission-rpc"
|
||||||
|
|||||||
36
src/lib.rs
36
src/lib.rs
@ -306,4 +306,38 @@ impl BodyString for reqwest::RequestBuilder {
|
|||||||
let body = rq.body().unwrap().as_bytes().unwrap();
|
let body = rq.body().unwrap().as_bytes().unwrap();
|
||||||
Ok(std::str::from_utf8(body)?.to_string())
|
Ok(std::str::from_utf8(body)?.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use std::env;
|
||||||
|
use dotenv::dotenv;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
pub async fn test_malformed_url() -> Result<()> {
|
||||||
|
dotenv().ok();
|
||||||
|
env_logger::init();
|
||||||
|
let url= env::var("TURL")?;
|
||||||
|
let basic_auth = BasicAuth{user: env::var("TUSER")?, password: env::var("TPWD")?};
|
||||||
|
let client = TransClient::with_auth(&url, basic_auth);
|
||||||
|
info!("Client is ready!");
|
||||||
|
let add: TorrentAddArgs = TorrentAddArgs {
|
||||||
|
filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrentt".to_string()),
|
||||||
|
..TorrentAddArgs::default()
|
||||||
|
};
|
||||||
|
match client.torrent_add(add).await {
|
||||||
|
Ok(res) => {
|
||||||
|
println!("Add result: {:?}", &res.is_ok());
|
||||||
|
println!("response: {:?}", &res);
|
||||||
|
assert!(!&res.is_ok());
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Error: {:#?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -96,6 +96,6 @@ impl RpcResponseArgument for Nothing {}
|
|||||||
#[derive(Deserialize, Debug, RustcEncodable)]
|
#[derive(Deserialize, Debug, RustcEncodable)]
|
||||||
pub struct TorrentAdded {
|
pub struct TorrentAdded {
|
||||||
#[serde(rename="torrent-added")]
|
#[serde(rename="torrent-added")]
|
||||||
pub torrent_added: Torrent
|
pub torrent_added: Option<Torrent>
|
||||||
}
|
}
|
||||||
impl RpcResponseArgument for TorrentAdded{}
|
impl RpcResponseArgument for TorrentAdded{}
|
||||||
Loading…
Reference in New Issue
Block a user