Refactor container definitions
This commit is contained in:
40
apps/container/src/containers.rs
Normal file
40
apps/container/src/containers.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
pub mod agent;
|
||||
pub mod db;
|
||||
|
||||
use std::{pin::Pin, sync::Arc};
|
||||
|
||||
use testcontainers::{ContainerAsync, GenericImage, TestcontainersError};
|
||||
|
||||
use crate::containers::{
|
||||
agent::AgentContainerInfo,
|
||||
db::{ContainerizedDBInfo, PreExistingDBInfo},
|
||||
};
|
||||
|
||||
pub type UnStartedContainer =
|
||||
Pin<Box<dyn Future<Output = Result<ContainerAsync<GenericImage>, TestcontainersError>> + Send>>;
|
||||
|
||||
pub type AgentConfigInfoType = ConfigInfoType<AgentContainerInfo, ()>;
|
||||
|
||||
pub type DBConfigInfoType = ConfigInfoType<ContainerizedDBInfo, PreExistingDBInfo>;
|
||||
|
||||
pub trait WithContainer {
|
||||
fn container(&self) -> &Arc<ContainerAsync<GenericImage>>;
|
||||
}
|
||||
|
||||
pub trait WithoutContainer {
|
||||
fn on_delete(&self);
|
||||
}
|
||||
|
||||
impl WithoutContainer for () {
|
||||
fn on_delete(&self) {}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ConfigInfoType<T, U>
|
||||
where
|
||||
T: WithContainer,
|
||||
U: WithoutContainer,
|
||||
{
|
||||
Containerized(T),
|
||||
PreExisting(U),
|
||||
}
|
||||
Reference in New Issue
Block a user