Add some test cases as integration tests
This commit is contained in:
parent
0d1f30665b
commit
64fef7a55e
|
@ -49,12 +49,11 @@ fn parse_stage(parser: &mut Pairs<Rule>) -> (Context, Vec<Step>) {
|
|||
debug!("Adding to context key: {}, value: {}", key, value);
|
||||
stage.properties.insert(key, value);
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Rule::steps => {
|
||||
let mut inner = parsed.into_inner();
|
||||
|
||||
|
@ -81,7 +80,7 @@ fn parse_stage(parser: &mut Pairs<Rule>) -> (Context, Vec<Step>) {
|
|||
(stage, steps)
|
||||
}
|
||||
|
||||
fn parse_pipeline_string(buffer: &str) -> Result<Pipeline, pest::error::Error<Rule>> {
|
||||
pub fn parse_pipeline_string(buffer: &str) -> Result<Pipeline, pest::error::Error<Rule>> {
|
||||
let mut parser = PipelineParser::parse(Rule::pipeline, buffer)?;
|
||||
let mut pipeline = Pipeline::default();
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
|
|
@ -0,0 +1 @@
|
|||
pipeline { }
|
|
@ -0,0 +1,9 @@
|
|||
pipeline {
|
||||
stages {
|
||||
stage {
|
||||
name = 'Build'
|
||||
steps {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
pipeline {
|
||||
stages {
|
||||
|
||||
stage {
|
||||
name = 'Build'
|
||||
steps {
|
||||
sh 'ls'
|
||||
}
|
||||
}
|
||||
|
||||
stage {
|
||||
name
|
||||
=
|
||||
'Deploy'
|
||||
|
||||
steps
|
||||
{
|
||||
sh 'ls -lah && touch deploy.lock'
|
||||
|
||||
sh 'make deploy'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
pipeline {
|
||||
stages {
|
||||
stage {
|
||||
name = 'Build'
|
||||
steps {
|
||||
sh 'ls'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
pipeline {
|
||||
stages {
|
||||
stage {
|
||||
name = 'Build'
|
||||
steps {
|
||||
sh script: 'ls'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This test module will test everything in test_data/valid
|
||||
*/
|
||||
use otto_parser::*;
|
||||
use std::fs::ReadDir;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn parse_file(path: &PathBuf) -> Result<otto_models::Pipeline, pest::error::Error<Rule>> {
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
let mut file = File::open(path).expect(&format!("Failed to open {:?}", path));
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)
|
||||
.expect("Failed to read file into string");
|
||||
|
||||
parse_pipeline_string(&contents)
|
||||
}
|
||||
|
||||
fn test_in_dir(dir: &mut ReadDir, can_parse: bool) {
|
||||
for entry in dir {
|
||||
if let Ok(entry) = entry {
|
||||
let path = entry.path();
|
||||
match path.as_path().extension() {
|
||||
Some(ext) => {
|
||||
if ext == "otto" {
|
||||
let result = parse_file(&path);
|
||||
|
||||
assert_eq!(can_parse, result.is_ok());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_valid_pipelines() {
|
||||
let mut dir = std::fs::read_dir("./test_data/valid").expect("Failed to read directory");
|
||||
test_in_dir(&mut dir, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_pipelines() {
|
||||
let mut dir = std::fs::read_dir("./test_data/invalid").expect("Failed to read directory");
|
||||
test_in_dir(&mut dir, false);
|
||||
}
|
Loading…
Reference in New Issue