feat: add testcontainers
This commit is contained in:
parent
01053da8d2
commit
7dabd46aa2
99
Cargo.lock
generated
99
Cargo.lock
generated
@ -546,6 +546,16 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bollard-stubs"
|
||||||
|
version = "1.42.0-rc.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed59b5c00048f48d7af971b71f800fdf23e858844a6f9e4d32ca72e9399e7864"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_with 1.14.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "borsh"
|
name = "borsh"
|
||||||
version = "1.3.1"
|
version = "1.3.1"
|
||||||
@ -1122,6 +1132,16 @@ dependencies = [
|
|||||||
"syn 2.0.50",
|
"syn 2.0.50",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling"
|
||||||
|
version = "0.13.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
|
||||||
|
dependencies = [
|
||||||
|
"darling_core 0.13.4",
|
||||||
|
"darling_macro 0.13.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling"
|
name = "darling"
|
||||||
version = "0.14.4"
|
version = "0.14.4"
|
||||||
@ -1142,6 +1162,20 @@ dependencies = [
|
|||||||
"darling_macro 0.20.8",
|
"darling_macro 0.20.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling_core"
|
||||||
|
version = "0.13.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
|
||||||
|
dependencies = [
|
||||||
|
"fnv",
|
||||||
|
"ident_case",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"strsim 0.10.0",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling_core"
|
name = "darling_core"
|
||||||
version = "0.14.4"
|
version = "0.14.4"
|
||||||
@ -1170,6 +1204,17 @@ dependencies = [
|
|||||||
"syn 2.0.50",
|
"syn 2.0.50",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling_macro"
|
||||||
|
version = "0.13.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
|
||||||
|
dependencies = [
|
||||||
|
"darling_core 0.13.4",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling_macro"
|
name = "darling_macro"
|
||||||
version = "0.14.4"
|
version = "0.14.4"
|
||||||
@ -3406,7 +3451,7 @@ dependencies = [
|
|||||||
"serde-value",
|
"serde-value",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_repr",
|
"serde_repr",
|
||||||
"serde_with",
|
"serde_with 2.3.3",
|
||||||
"tap",
|
"tap",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tracing",
|
"tracing",
|
||||||
@ -3537,6 +3582,8 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serial_test",
|
"serial_test",
|
||||||
|
"testcontainers",
|
||||||
|
"testcontainers-modules",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tl",
|
"tl",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -4421,6 +4468,16 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_with"
|
||||||
|
version = "1.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_with_macros 1.5.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_with"
|
name = "serde_with"
|
||||||
version = "2.3.3"
|
version = "2.3.3"
|
||||||
@ -4433,10 +4490,22 @@ dependencies = [
|
|||||||
"indexmap 1.9.3",
|
"indexmap 1.9.3",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_with_macros",
|
"serde_with_macros 2.3.3",
|
||||||
"time",
|
"time",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_with_macros"
|
||||||
|
version = "1.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082"
|
||||||
|
dependencies = [
|
||||||
|
"darling 0.13.4",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_with_macros"
|
name = "serde_with_macros"
|
||||||
version = "2.3.3"
|
version = "2.3.3"
|
||||||
@ -5122,6 +5191,32 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "testcontainers"
|
||||||
|
version = "0.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f83d2931d7f521af5bae989f716c3fa43a6af9af7ec7a5e21b59ae40878cec00"
|
||||||
|
dependencies = [
|
||||||
|
"bollard-stubs",
|
||||||
|
"futures",
|
||||||
|
"hex 0.4.3",
|
||||||
|
"hmac",
|
||||||
|
"log",
|
||||||
|
"rand",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"sha2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "testcontainers-modules"
|
||||||
|
version = "0.3.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d0334776e1e8ee7c504a922c5236daf865ffe413aa630d84ae91dcce0b10bc3"
|
||||||
|
dependencies = [
|
||||||
|
"testcontainers",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "textwrap"
|
name = "textwrap"
|
||||||
version = "0.15.2"
|
version = "0.15.2"
|
||||||
|
@ -4,9 +4,20 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[lib]
|
||||||
|
name = "recorder"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "recorder_cli"
|
||||||
|
path = "src/bin/main.rs"
|
||||||
|
required-features = []
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
testcontainers = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
loco-rs = { version = "0.3.1" }
|
loco-rs = { version = "0.3.1" }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
@ -49,17 +60,10 @@ html-escape = "0.2.13"
|
|||||||
opendal = "0.45.0"
|
opendal = "0.45.0"
|
||||||
librqbit-core = "3.5.0"
|
librqbit-core = "3.5.0"
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "recorder"
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "recorder_cli"
|
|
||||||
path = "src/bin/main.rs"
|
|
||||||
required-features = []
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serial_test = "2.0.0"
|
serial_test = "2.0.0"
|
||||||
rstest = "0.18.2"
|
rstest = "0.18.2"
|
||||||
loco-rs = { version = "0.3.1", features = ["testing"] }
|
loco-rs = { version = "0.3.1", features = ["testing"] }
|
||||||
insta = { version = "1.34.0", features = ["redactions", "yaml", "filters"] }
|
insta = { version = "1.34.0", features = ["redactions", "yaml", "filters"] }
|
||||||
|
testcontainers = { version = "0.15.0" }
|
||||||
|
testcontainers-modules = { version = "0.3.5" }
|
@ -411,8 +411,9 @@ impl Debug for QBittorrentDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
pub mod tests {
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use testcontainers::core::ExecCommand;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -424,8 +425,48 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "testcontainers")]
|
||||||
|
pub fn create_qbit_testcontainer() -> testcontainers::RunnableImage<testcontainers::GenericImage>
|
||||||
|
{
|
||||||
|
let image = testcontainers::RunnableImage::from(
|
||||||
|
testcontainers::GenericImage::new("linuxserver/qbittorrent", "latest")
|
||||||
|
.with_wait_for(testcontainers::core::WaitFor::message_on_stderr(
|
||||||
|
"Connection to localhost",
|
||||||
|
))
|
||||||
|
.with_env_var("WEBUI_PORT", "8080")
|
||||||
|
.with_env_var("TZ", "Asia/Singapore")
|
||||||
|
.with_env_var("TORRENTING_PORT", "6881")
|
||||||
|
.with_exposed_port(8080)
|
||||||
|
.with_exposed_port(6881),
|
||||||
|
);
|
||||||
|
|
||||||
|
image
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "testcontainers"))]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_add_torrents_and_get_info() {
|
async fn test_qbittorrent_downloader() {
|
||||||
|
test_qbittorrent_downloader_impl().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @TODO: not support now, testcontainers crate not support to read logs to get
|
||||||
|
// password
|
||||||
|
#[cfg(feature = "testcontainers")]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_qbittorrent_downloader() {
|
||||||
|
let docker = testcontainers::clients::Cli::default();
|
||||||
|
let image = create_qbit_testcontainer();
|
||||||
|
|
||||||
|
let container = docker.run(image);
|
||||||
|
|
||||||
|
let mut exec = ExecCommand::default();
|
||||||
|
|
||||||
|
container.exec(exec);
|
||||||
|
|
||||||
|
test_qbittorrent_downloader_impl().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn test_qbittorrent_downloader_impl() {
|
||||||
let base_save_path = VFSSubPath::new(get_tmp_qbit_test_folder());
|
let base_save_path = VFSSubPath::new(get_tmp_qbit_test_folder());
|
||||||
|
|
||||||
let downloader = QBittorrentDownloader::from_downloader_model(downloaders::Model {
|
let downloader = QBittorrentDownloader::from_downloader_model(downloaders::Model {
|
||||||
@ -433,7 +474,7 @@ mod tests {
|
|||||||
updated_at: Default::default(),
|
updated_at: Default::default(),
|
||||||
id: 0,
|
id: 0,
|
||||||
category: DownloaderCategory::QBittorrent,
|
category: DownloaderCategory::QBittorrent,
|
||||||
endpoint: "http://127.0.0.1:8080".to_string(),
|
endpoint: "http://localhost:8080".to_string(),
|
||||||
password: "".to_string(),
|
password: "".to_string(),
|
||||||
username: "".to_string(),
|
username: "".to_string(),
|
||||||
subscriber_id: 0,
|
subscriber_id: 0,
|
||||||
@ -453,7 +494,7 @@ mod tests {
|
|||||||
"https://mikanani.me/Download/20240301/47ee2d69e7f19af783ad896541a07b012676f858.torrent"
|
"https://mikanani.me/Download/20240301/47ee2d69e7f19af783ad896541a07b012676f858.torrent"
|
||||||
).await.unwrap();
|
).await.unwrap();
|
||||||
|
|
||||||
let mut save_path = base_save_path.join(format!(
|
let save_path = base_save_path.join(format!(
|
||||||
"test_add_torrents_{}",
|
"test_add_torrents_{}",
|
||||||
chrono::Utc::now().timestamp()
|
chrono::Utc::now().timestamp()
|
||||||
));
|
));
|
||||||
|
Loading…
Reference in New Issue
Block a user