Add the necessary serde mappings for the urci.yml format as it stands now
This commit is contained in:
parent
a70b49560e
commit
90f8018d7c
|
@ -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#"---
|
||||
|
|
Loading…
Reference in New Issue