cinderella

[unmaintained] simple CI engine
Log | Files | Refs | README | LICENSE

commit 238ccfb2b65d08c057255bdff5f9b945f12a7385
parent b827611b62fa7c90721231de6fb5dddb86ac691f
Author: Stefan Koch <programming@stefan-koch.name>
Date:   Tue, 17 Sep 2019 19:55:58 +0200

add more unit tests to execution

Diffstat:
Msrc/execution.rs | 46++++++++++++++++++++++++++++++++++++++++------
1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/src/execution.rs b/src/execution.rs @@ -24,7 +24,7 @@ pub fn execute<W: Write>( } } -pub fn execute_pipeline<W: Write>( +fn execute_pipeline<W: Write>( pipeline: &pipeline::Pipeline, variables: &HashMap<String, String>, stdout: &mut W) @@ -87,6 +87,13 @@ mod tests { use std::collections::HashMap; use crate::pipeline::Pipeline; + fn execute_stringout(pipeline: Pipeline, + variables: HashMap<String, String>) -> String { + let mut stdout = Vec::new(); + execute(&vec![pipeline], &variables, &mut stdout); + String::from_utf8(stdout.iter().map(|&c| c as u8).collect()).unwrap() + } + #[test] fn test_execute_pipeline() { let pipeline = Pipeline { @@ -96,13 +103,40 @@ mod tests { }; let variables = HashMap::new(); - // Dummy stdout - let mut stdout = Vec::new(); - execute_pipeline(&pipeline, &variables, &mut stdout); - - let result = String::from_utf8(stdout.iter().map(|&c| c as u8).collect()).unwrap(); + let result = execute_stringout(pipeline, variables); assert!(result.contains("Executing pipeline \"my-test\"")); assert!(result.contains("this is my test")); } + + #[test] + fn test_pipeline_with_variables() { + let pipeline = Pipeline { + name: String::from("my-test"), + commands: vec!["echo '{{ myvar }}'".to_string()], + when: None, + }; + let mut variables = HashMap::new(); + variables.insert(String::from("myvar"), String::from("some value")); + + let result = execute_stringout(pipeline, variables); + + assert!(result.contains("some value")); + } + + #[test] + fn test_conditional_pipeline() { + let pipeline = Pipeline { + name: String::from("my-test"), + commands: vec!["echo 'Building non-master'".to_string()], + when: Some(String::from("\"{{ branch }}\" != \"master\"")), + }; + let mut variables = HashMap::new(); + variables.insert(String::from("branch"), String::from("master")); + + let result = execute_stringout(pipeline, variables); + + println!("{}", result); + assert!(!result.contains("non-master")); + } }