@@ -1,9 +1,12 @@
|
||||
use std::{cmp::Ordering, path::Path};
|
||||
|
||||
use cuddle_clusters::process::ProcessOpts;
|
||||
use cuddle_clusters::{process::ProcessOpts, ConcreteComponent, IntoComponent};
|
||||
use walkdir::DirEntry;
|
||||
|
||||
pub(crate) async fn run_test(name: &str) -> anyhow::Result<()> {
|
||||
pub(crate) async fn run_test_with_components(
|
||||
name: &str,
|
||||
components: Vec<impl IntoComponent>,
|
||||
) -> anyhow::Result<()> {
|
||||
let _ = tracing_subscriber::fmt::try_init();
|
||||
|
||||
println!("running for: {name}");
|
||||
@@ -17,17 +20,25 @@ pub(crate) async fn run_test(name: &str) -> anyhow::Result<()> {
|
||||
let expected = test_folder.join("expected");
|
||||
tokio::fs::create_dir_all(&expected).await?;
|
||||
|
||||
cuddle_clusters::process_opts(ProcessOpts {
|
||||
path: test_folder.clone(),
|
||||
output: actual.clone(),
|
||||
})
|
||||
let components: Vec<_> = components.into_iter().map(|p| p.into_component()).collect();
|
||||
|
||||
cuddle_clusters::process_opts(
|
||||
components.clone(),
|
||||
ProcessOpts {
|
||||
path: test_folder.clone(),
|
||||
output: actual.clone(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
if std::env::var("TEST_OVERRIDE") == Ok("true".to_string()) {
|
||||
cuddle_clusters::process_opts(ProcessOpts {
|
||||
path: test_folder,
|
||||
output: expected.clone(),
|
||||
})
|
||||
cuddle_clusters::process_opts(
|
||||
components,
|
||||
ProcessOpts {
|
||||
path: test_folder,
|
||||
output: expected.clone(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -36,6 +47,10 @@ pub(crate) async fn run_test(name: &str) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn run_test(name: &str) -> anyhow::Result<()> {
|
||||
run_test_with_components(name, Vec::<ConcreteComponent>::new()).await
|
||||
}
|
||||
|
||||
async fn compare(expected: &Path, actual: &Path) -> anyhow::Result<()> {
|
||||
let mut exp = walk_dir(expected)?;
|
||||
let mut act = walk_dir(actual)?;
|
||||
|
49
crates/cuddle-clusters/tests/cuddle_vars.rs
Normal file
49
crates/cuddle-clusters/tests/cuddle_vars.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use cuddle_clusters::catalog::cuddle_vars::{CuddleVariable, CuddleVariables, CuddleVars};
|
||||
use similar_asserts::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn can_load_cuddle_file() -> anyhow::Result<()> {
|
||||
let current_dir = std::env::current_dir()?.join("tests");
|
||||
|
||||
let vars = CuddleVars::new(¤t_dir.join("cuddle_vars/basic/")).await?;
|
||||
|
||||
assert_eq!(
|
||||
CuddleVars {
|
||||
variables: CuddleVariables(HashMap::from([
|
||||
("service".into(), CuddleVariable::String("basic".into())),
|
||||
(
|
||||
"some".into(),
|
||||
CuddleVariable::Object(Box::new(CuddleVariables(HashMap::from([
|
||||
("other".into(), CuddleVariable::String("item".into())),
|
||||
(
|
||||
"nested".into(),
|
||||
CuddleVariable::Object(Box::new(CuddleVariables(HashMap::from([(
|
||||
"item".into(),
|
||||
CuddleVariable::String("item".into())
|
||||
)]))))
|
||||
),
|
||||
(
|
||||
"array".into(),
|
||||
CuddleVariable::Array(vec![CuddleVariable::Object(Box::new(
|
||||
CuddleVariables(HashMap::from([(
|
||||
"item".into(),
|
||||
CuddleVariable::Object(Box::new(CuddleVariables(
|
||||
HashMap::from([(
|
||||
"item".into(),
|
||||
CuddleVariable::String("item".into()),
|
||||
)])
|
||||
)))
|
||||
)]))
|
||||
))])
|
||||
)
|
||||
]))))
|
||||
)
|
||||
]))
|
||||
},
|
||||
vars
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
10
crates/cuddle-clusters/tests/cuddle_vars/basic/cuddle.yaml
Normal file
10
crates/cuddle-clusters/tests/cuddle_vars/basic/cuddle.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
vars:
|
||||
service: basic
|
||||
some:
|
||||
other: item
|
||||
nested:
|
||||
item: item
|
||||
array:
|
||||
- item:
|
||||
item: item
|
||||
|
@@ -1,8 +1,11 @@
|
||||
pub mod common;
|
||||
|
||||
mod can_run_for_env;
|
||||
mod cuddle_vars;
|
||||
|
||||
use crate::common::run_test;
|
||||
use cuddle_clusters::catalog::cuddle_vars::CuddleVars;
|
||||
|
||||
use crate::common::{run_test, run_test_with_components};
|
||||
|
||||
#[tokio::test]
|
||||
async fn raw_files() -> anyhow::Result<()> {
|
||||
@@ -37,3 +40,16 @@ async fn environment() -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn with_cuddle_vars() -> anyhow::Result<()> {
|
||||
let current_dir = std::env::current_dir()?.join("tests/with_cuddle_vars");
|
||||
|
||||
run_test_with_components(
|
||||
"with_cuddle_vars",
|
||||
vec![CuddleVars::new(¤t_dir).await?],
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -0,0 +1,5 @@
|
||||
vars:
|
||||
service: service
|
||||
|
||||
cuddle/clusters:
|
||||
dev:
|
@@ -0,0 +1,2 @@
|
||||
service: service
|
||||
|
@@ -0,0 +1,3 @@
|
||||
service: {{ vars.cuddle_vars.service }}
|
||||
|
||||
|
Reference in New Issue
Block a user