Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion tests/qbittorrent.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hightorrent::{MagnetLink, SingleTarget};
use hightorrent::{MagnetLink, SingleTarget, TorrentFile};
use hightorrent_api::{Api, ApiError, QBittorrentClient};
use tokio::sync::OnceCell;

Expand All @@ -23,6 +23,7 @@ static LOCK: OnceCell<Mutex<QBittorrentClient>> = 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";
Expand Down Expand Up @@ -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;
Expand Down
Loading