Add the necessary serde mappings for the urci.yml format as it stands now

This commit is contained in:
R Tyler Croy 2020-08-15 14:38:53 -07:00
parent a70b49560e
commit 90f8018d7c
2 changed files with 31 additions and 4 deletions

View File

@ -4,13 +4,14 @@
*/
use serde::de::{Deserialize, Deserializer};
use std::str::FromStr;
use std::collections::HashMap;
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Config {
pub projects: Vec<Project>,
pub agents: Vec<Agent>,
pub handlers: Vec<Handler>,
pub handlers: HashMap<String, Handler>,
}
#[derive(Debug, Deserialize)]
@ -48,11 +49,26 @@ pub struct Scm {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Agent {}
pub enum AgentType {
Local,
Ssh,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Handler {}
pub struct Agent {
name: String,
description: String,
r#type: AgentType,
params: Option<HashMap<String, String>>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Handler {
filename: String,
defaults: Option<HashMap<String, String>>,
}
fn deserialize_cron_schedule<'de, D>(deserializer: D) -> Result<Option<cron::Schedule>, D::Error>
where
@ -70,8 +86,19 @@ where
#[cfg(test)]
mod tests {
use std::fs::File;
use std::io::Read;
use super::*;
#[test]
fn test_deserialize_example_config() {
let mut f = File::open("urci.yml").unwrap();
let mut yaml = String::new();
f.read_to_string(&mut yaml).expect("Failed to read into string");
let _config: Config = serde_yaml::from_str(&yaml).expect("Failed to parse the yaml");
}
#[test]
fn test_cron_deserialize() {
let trigger_yaml = r#"---

View File

@ -5,7 +5,7 @@
projects:
- name: hotdog
trigger:
cron: '*/10 * * * *'
cron: '10 * * * * *'
# The different types of handlers should be documented elsewhere. In this
# case, the project is expected to use a simple .travis-ci.yml
handler: travis-ci