Introduce origin config

This commit is contained in:
Brian Picciano 2023-07-09 14:07:07 +02:00
parent 254d9c63d0
commit 9c1bdc1e8a
4 changed files with 26 additions and 9 deletions

View File

@ -73,7 +73,11 @@ async fn main() {
)
.init();
let origin_store = domani::origin::git::FSStore::new(config.origin_store_git_dir_path)
let origin_config = domani::origin::Config {
store_dir_path: config.origin_store_git_dir_path,
};
let origin_store = domani::origin::git::FSStore::new(&origin_config)
.expect("git origin store initialization failed");
let domain_checker = domani::domain::checker::DNSChecker::new(

View File

@ -1,13 +1,15 @@
use crate::error::unexpected;
use crate::util;
use std::sync;
mod config;
mod descr;
pub mod git;
pub mod mux;
mod descr;
pub use config::*;
pub use descr::Descr;
use crate::error::unexpected;
use crate::util;
use std::sync;
#[derive(thiserror::Error, Clone, Debug, PartialEq)]
pub enum SyncError {
#[error("invalid url")]

7
src/origin/config.rs Normal file
View File

@ -0,0 +1,7 @@
use serde::Deserialize;
use std::path;
#[derive(Deserialize)]
pub struct Config {
pub store_dir_path: path::PathBuf,
}

View File

@ -34,7 +34,8 @@ pub struct FSStore {
}
impl FSStore {
pub fn new(dir_path: PathBuf) -> io::Result<Self> {
pub fn new(config: &origin::Config) -> io::Result<Self> {
let dir_path = config.store_dir_path.clone();
fs::create_dir_all(&dir_path)?;
Ok(Self {
dir_path,
@ -336,13 +337,16 @@ impl super::Store for FSStore {
#[cfg(test)]
mod tests {
use crate::origin::{self, Store};
use crate::origin::{self, Config, Store};
use futures::StreamExt;
use tempdir::TempDir;
#[tokio::test]
async fn basic() {
let tmp_dir = TempDir::new("origin_store_git").unwrap();
let config = Config {
store_dir_path: tmp_dir.path().to_path_buf(),
};
let curr_dir = format!("file://{}", std::env::current_dir().unwrap().display());
@ -356,7 +360,7 @@ mod tests {
branch_name: String::from("some_other_branch"),
};
let store = super::FSStore::new(tmp_dir.path().to_path_buf()).expect("store created");
let store = super::FSStore::new(&config).expect("store created");
store.sync(&descr).expect("sync should succeed");
store.sync(&descr).expect("second sync should succeed");