use std::collections::HashMap;
use std::path::PathBuf;
use digdigdig3::{AccountType, ExchangeId};
use super::StreamKind;
#[derive(Debug, Clone)]
pub enum DataSource {
Binary { storage_root: PathBuf },
Json { storage_root: PathBuf },
Rest {
exchange: ExchangeId,
account_type: AccountType,
},
Mixed {
per_stream: HashMap<StreamKind, Box<DataSource>>,
},
}
#[cfg(test)]
mod tests {
use super::DataSource;
use crate::data_loader::StreamKind;
use digdigdig3::{AccountType, ExchangeId};
use std::collections::HashMap;
use std::path::PathBuf;
#[test]
fn binary_variant_stores_path() {
let ds = DataSource::Binary {
storage_root: PathBuf::from("/tmp/data"),
};
match ds {
DataSource::Binary { storage_root } => {
assert_eq!(storage_root, PathBuf::from("/tmp/data"));
}
_ => panic!("expected Binary"),
}
}
#[test]
fn json_variant_stores_path() {
let ds = DataSource::Json {
storage_root: PathBuf::from("/tmp/json_data"),
};
match ds {
DataSource::Json { storage_root } => {
assert_eq!(storage_root, PathBuf::from("/tmp/json_data"));
}
_ => panic!("expected Json"),
}
}
#[test]
fn rest_variant_stores_exchange_and_account_type() {
let ds = DataSource::Rest {
exchange: ExchangeId::Binance,
account_type: AccountType::FuturesCross,
};
match ds {
DataSource::Rest { exchange, account_type } => {
assert_eq!(exchange, ExchangeId::Binance);
assert_eq!(account_type, AccountType::FuturesCross);
}
_ => panic!("expected Rest"),
}
}
#[test]
fn mixed_variant_stores_per_stream() {
let mut map: HashMap<StreamKind, Box<DataSource>> = HashMap::new();
map.insert(
StreamKind::Funding,
Box::new(DataSource::Binary {
storage_root: PathBuf::from("/tmp/binary"),
}),
);
map.insert(
StreamKind::OpenInterest,
Box::new(DataSource::Json {
storage_root: PathBuf::from("/tmp/json"),
}),
);
let ds = DataSource::Mixed { per_stream: map };
match ds {
DataSource::Mixed { per_stream } => {
assert!(per_stream.contains_key(&StreamKind::Funding));
assert!(per_stream.contains_key(&StreamKind::OpenInterest));
}
_ => panic!("expected Mixed"),
}
}
}