refactor: split out testcontainers-rs-ext

This commit is contained in:
2025-04-05 19:51:59 +08:00
parent a3609696c7
commit 376d2b28d3
12 changed files with 1202 additions and 1443 deletions

View File

@@ -0,0 +1,10 @@
[package]
name = "testing-torrents"
version = "0.1.0"
edition = "2024"
[dependencies]
serde = { version = "1", features = ["derive"] }
testcontainers = { version = "0.23.3" }
testcontainers-modules = { version = "0.11.4" }
testcontainers-ext = { version = "0.1.0", features = ["tracing"] }

View File

@@ -0,0 +1,44 @@
use serde::{Deserialize, Serialize};
use testcontainers::{
GenericImage,
core::{ContainerPort, WaitFor},
};
use testcontainers_ext::{ImageDefaultLogConsumerExt, ImagePruneExistedLabelExt};
use testcontainers_modules::testcontainers::ImageExt;
#[derive(Serialize)]
pub struct TestingTorrentFileItem {
pub path: String,
pub size: u64,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TestTorrentRequest {
pub id: String,
pub file_list: Vec<TestingTorrentFileItem>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TestTorrentResponse {
pub torrent_url: String,
pub magnet_url: String,
pub hash: String,
}
pub async fn create_testcontainers() -> Result<
testcontainers::ContainerRequest<testcontainers::GenericImage>,
testcontainers::TestcontainersError,
> {
let container = GenericImage::new("ghcr.io/dumtruck/konobangu-testing-torrents", "latest")
.with_wait_for(WaitFor::message_on_stdout("Listening on"))
.with_mapped_port(6080, ContainerPort::Tcp(6080))
.with_mapped_port(6081, ContainerPort::Tcp(6081))
.with_mapped_port(6082, ContainerPort::Tcp(6082))
.with_default_log_consumer()
.with_prune_existed_label("konobangu", "testing-torrents", true, true)
.await?;
Ok(container)
}