From 12a9779cef60a40df525e2d012412cd856c192d5 Mon Sep 17 00:00:00 2001 From: angrynode Date: Tue, 2 Jun 2026 12:58:59 +0200 Subject: [PATCH] tests: Add test with actual torrent file for adding torrents --- tests/qbittorrent.rs | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/qbittorrent.rs b/tests/qbittorrent.rs index b6f2f21..be31553 100644 --- a/tests/qbittorrent.rs +++ b/tests/qbittorrent.rs @@ -1,4 +1,4 @@ -use hightorrent::{MagnetLink, SingleTarget}; +use hightorrent::{MagnetLink, SingleTarget, TorrentFile}; use hightorrent_api::{Api, ApiError, QBittorrentClient}; use tokio::sync::OnceCell; @@ -23,6 +23,7 @@ static LOCK: OnceCell> = OnceCell::const_new(); // static HYBRID_NAME: &str = "bittorrent-v1-v2-hybrid-test"; static V1_MAGNET: &str = "magnet:?xt=urn:btih:2c6e17017f6bb87125b2ba98c56a67f8ffe7e02c&dn=tails-amd64-5.6-img&tr=udp%3a%2f%2ftracker.torrent.eu.org%3a451&tr=udp%3a%2f%2ftracker.coppersurfer.tk%3a6969"; +static V1_TORRENT: &[u8] = include_bytes!("tails-amd64-5.6.img.torrent"); // static V1_TORRENT: &[u8] = include_bytes!("tails-amd64-5.6.img.torrent"); static V1_V1HASH: &str = "2c6e17017f6bb87125b2ba98c56a67f8ffe7e02c"; static V1_ID: &str = "2c6e17017f6bb87125b2ba98c56a67f8ffe7e02c"; @@ -98,6 +99,58 @@ async fn magnet_v1() -> Result<(), ApiError> { Ok(()) } +#[tokio::test] +async fn torrent_v1() -> Result<(), ApiError> { + let api = client().await; + let target = SingleTarget::new(V1_V1HASH).unwrap(); + + // Check torrent does not exist + let list = api.list().await?; + let entry = list.get(&target); + + // If the test suite is run in an existing qBittorrent instance, + // the magnet may already be there. + let entry = if entry.is_some() { + api.remove(&target, false).await?; + let list = api.list().await?; + list.get(&target) + } else { + entry + }; + assert!(entry.is_none()); + + // Add torrent + api.add() + .torrent(TorrentFile::from_slice(V1_TORRENT).unwrap()) + .paused(true) + .send() + .await?; + + // Check torrent does exist now + let list = api.list().await?; + let entry = list.get(&target); + assert!(entry.is_some()); + + let entry = entry.unwrap(); + assert_eq!(entry.hash.id().as_str(), V1_ID); + assert_eq!(entry.name.as_str(), V1_NAME); + + // Make sure torrent is paused + // For some reason, the torrent is in `checkingResumeData` state and not `stoppedDL` here + let possibles_states = &["stoppedDL", "checkingResumeData"]; + assert!(possibles_states.contains(&entry.state.as_str())); + + // Remove torrent + api.remove(&target, true).await?; + + // Check torrent does not exist anymore + let list = api.list().await?; + let entry = list.get(&target); + assert!(entry.is_none()); + + Ok(()) +} + #[tokio::test] async fn version() -> Result<(), ApiError> { let api = client().await;