This commit is contained in:
Lev Kokotov
2022-02-08 17:08:17 -08:00
parent 95c2d593cc
commit edf6a69ca4
7 changed files with 22 additions and 70 deletions

View File

@@ -1,10 +1,10 @@
use serde_derive::Deserialize;
use std::collections::HashMap;
use std::path::Path;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
use toml;
use std::collections::HashMap;
use crate::errors::Error;
#[derive(Clone, PartialEq, Hash, std::cmp::Eq, Debug)]
@@ -62,16 +62,6 @@ pub async fn parse(path: &str) -> Result<Config, Error> {
}
};
// let config: toml::Value = match toml::from_str(&contents) {
// Ok(config) => config,
// Err(err) => {
// println!("> Config error: {:?}", err);
// return Err(Error::BadConfig);
// }
// };
// println!("Config: {:?}", config);
let config: Config = match toml::from_str(&contents) {
Ok(config) => config,
Err(err) => {
@@ -82,3 +72,16 @@ pub async fn parse(path: &str) -> Result<Config, Error> {
Ok(config)
}
#[cfg(test)]
mod test {
use super::*;
#[tokio::test]
async fn test_config() {
let config = parse("pgcat.toml").await.unwrap();
assert_eq!(config.general.pool_size, 15);
assert_eq!(config.shards.len(), 3);
assert_eq!(config.shards["1"].servers[0].0, "127.0.0.1");
}
}