Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Nov 4, 2023
1 parent 1303bf6 commit a5d8f78
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
45 changes: 22 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,8 @@ mod tests {
let bombadil = Bombadil::from_settings(NoGpg)?;

assert_that!(bombadil.dots.get("maven")).is_some();
assert_eq!(toml::to_string(&bombadil.vars)?, "hello = \"world\"\n");
let toml = toml::to_string(&bombadil.vars)?;
assert!(toml.contains("hello = \"world\"\n"));

Ok(())
}
Expand All @@ -851,7 +852,6 @@ mod tests {
mod metadata {
use super::*;
use crate::Mode::NoGpg;
use indoc::indoc;
use pretty_assertions::assert_eq;
use std::io::BufWriter;

Expand All @@ -872,18 +872,16 @@ mod tests {

// Act
let result = bombadil.print_metadata_to_string(MetadataType::Vars)?;
let json: Value = serde_json::from_str(&result)?;

// Assert
assert_eq!(json.get("red"), Some(&Value::String("#FF0000".to_string())));
assert_eq!(
result,
indoc! {
r##"
{
"red": "#FF0000",
"black": "#000000",
"green": "#008000"
}"##
}
json.get("black"),
Some(&Value::String("#000000".to_string()))
);
assert_eq!(
json.get("green"),
Some(&Value::String("#008000".to_string()))
);

Ok(())
Expand All @@ -896,19 +894,20 @@ mod tests {

// Act
let result = bombadil.print_metadata_to_string(MetadataType::Vars)?;
let json: Value = serde_json::from_str(&result)?;

// Assert
assert_eq!(json.get("red"), Some(&Value::String("#FF0000".to_string())));
assert_eq!(
result,
indoc! {
r##"
{
"red": "#FF0000",
"black": "#000000",
"green": "#008000",
"yellow": "#f0f722"
}"##
}
json.get("black"),
Some(&Value::String("#000000".to_string()))
);
assert_eq!(
json.get("green"),
Some(&Value::String("#008000".to_string()))
);
assert_eq!(
json.get("yellow"),
Some(&Value::String("#f0f722".to_string()))
);

Ok(())
Expand Down
12 changes: 11 additions & 1 deletion src/templating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ use std::io::BufReader;
use std::path::{Path, PathBuf};
use tera::{Context, Map, Tera, Value};

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Variables {
/// holds the values defined in template.toml
pub(crate) inner: Value,
}

impl Default for Variables {
fn default() -> Self {
Self {
inner: Value::Object(Map::new()),
}
}
}

impl Variables {
pub(crate) fn has_secrets(&self) -> bool {
self.inner
Expand Down Expand Up @@ -67,6 +75,7 @@ impl Variables {
None => {
let mut secrets = tera::Map::new();
secrets.insert(key.to_string(), Value::String(encrypted.to_string()));
println!("{}", self.inner);
let Some(vars) = self.inner.as_object_mut() else {
panic!("Variables should be a Value::Object");
};
Expand Down Expand Up @@ -180,6 +189,7 @@ impl Variables {
}

pub(crate) fn with_os(mut self) -> Self {
println!("{}", self.inner);
let Some(vars) = self.inner.as_object_mut() else {
panic!("Variables should be a Value::Object");
};
Expand Down

0 comments on commit a5d8f78

Please sign in to comment.