Skip to content

Commit

Permalink
Dummy provider: override offer properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mwalkiewicz committed Sep 17, 2024
1 parent f9806e1 commit 8a4f9e8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/process/dummy.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fs;
use std::path::PathBuf;
use std::process::{ExitStatus, Stdio};
use std::sync::Arc;
Expand All @@ -14,6 +15,8 @@ use crate::offer_template;

use super::{Runtime, RuntimeConfig};

const OFFER_OVERRIDE_FILE_PATH_ENV: &str = "OFFER_OVERRIDE_FILE_PATH";

#[derive(Clone)]
pub struct Dummy {
child: Arc<Mutex<Child>>,
Expand Down Expand Up @@ -87,10 +90,27 @@ impl Runtime for Dummy {
}

fn test(_config: &Self::CONFIG) -> anyhow::Result<()> {
Ok(())
Dummy::read_overrides().map(|_| ())
}

fn offer_template(config: &Self::CONFIG) -> anyhow::Result<OfferTemplate> {
offer_template::template(config)
let template = offer_template::template(config)?;
if let Ok(Some(overrides)) = Dummy::read_overrides() {
Ok(template.patch(overrides))
} else {
Ok(template)
}
}
}

impl Dummy {
fn read_overrides() -> anyhow::Result<Option<OfferTemplate>> {
if let Ok(override_json_path) = std::env::var(OFFER_OVERRIDE_FILE_PATH_ENV) {
let file = fs::File::open(override_json_path)?;
let overrides: OfferTemplate = serde_json::from_reader(file)?;
Ok(Some(overrides))
} else {
Ok(None)
}
}
}

0 comments on commit 8a4f9e8

Please sign in to comment.