From e471d69946fda4e532683eec394b691f5d007eb2 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 19 Nov 2018 08:07:22 +0100 Subject: [PATCH] section_config.rs: add some test code --- src/section_config.rs | 60 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/section_config.rs b/src/section_config.rs index 9df9060c..910e20b5 100644 --- a/src/section_config.rs +++ b/src/section_config.rs @@ -1,9 +1,67 @@ +use std::fs::File; +use std::io::Read; +use std::collections::HashMap; +use serde_json::{json, Value}; + +pub struct SectionConfigPlugin { + type_name: String, +} -struct SectionConfig { +pub struct SectionConfig { + plugins: HashMap, + parse_section_header: fn(String) -> Value, } impl SectionConfig { + pub fn new() -> Self { + Self { + plugins: HashMap::new(), + parse_section_header: SectionConfig::default_parse_section_header, + } + } + + pub fn parse(&self, filename: &str, raw: &str) { + + for line in raw.lines() { + println!("LINE:{}", line); + } + } + + fn default_parse_section_header(line: String) -> Value { + + let config = json!({}); + + config + } + + +} + + +// cargo test test_section_config1 -- --nocapture +#[test] +fn test_section_config1() { + + let filename = "storage.cfg"; + + //let mut file = File::open(filename).expect("file not found"); + //let mut contents = String::new(); + //file.read_to_string(&mut contents).unwrap(); + + let config = SectionConfig::new(); + + + let raw = r" +lvmthin: local-lvm + thinpool data + vgname pve5 + content rootdir,images +"; + + config.parse(filename, &raw); + + }