Externalize the test table
I'm beginning work on the file reading functions, so I need some files to read in my tests. I'll also need the WholeFile struct to compare against. The input string has been moved out into a file and put back into the test fixture with `include_str!()`. The WholeFile construction has been moved to a util function so I can reuse it in another test.
This commit is contained in:
@@ -145,6 +145,43 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
// Util for generating a reference struct
|
||||||
|
fn gen_expected_struct() -> WholeFile {
|
||||||
|
WholeFile {
|
||||||
|
all: PartialConfig {
|
||||||
|
project_path: None,
|
||||||
|
gitea_url: Some(String::from("http://localhost:3000")),
|
||||||
|
owner: None,
|
||||||
|
repo: None,
|
||||||
|
token: Some(String::from("fake-token"))
|
||||||
|
},
|
||||||
|
project_overrides: vec![
|
||||||
|
PartialConfig {
|
||||||
|
project_path: Some(String::from("/home/robert/projects/gt-tool")),
|
||||||
|
gitea_url: None,
|
||||||
|
owner: Some(String::from("robert")),
|
||||||
|
repo: Some(String::from("gt-tool")),
|
||||||
|
token: None,
|
||||||
|
},
|
||||||
|
PartialConfig {
|
||||||
|
project_path: Some(String::from("/home/robert/projects/rcalc")),
|
||||||
|
gitea_url: None,
|
||||||
|
owner: Some(String::from("jamis")),
|
||||||
|
repo: Some(String::from("rcalc")),
|
||||||
|
token: None,
|
||||||
|
},
|
||||||
|
PartialConfig {
|
||||||
|
project_path: Some(String::from("/home/robert/projects/rcalc-builders")),
|
||||||
|
gitea_url: None,
|
||||||
|
owner: Some(String::from("jamis")),
|
||||||
|
repo: Some(String::from("rcalc")),
|
||||||
|
token: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_single_prop() -> Result<()> {
|
fn read_single_prop() -> Result<()> {
|
||||||
let fx_input_str = "owner = \"dingus\"";
|
let fx_input_str = "owner = \"dingus\"";
|
||||||
@@ -185,56 +222,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_config_string_ok() -> Result<()> {
|
fn read_config_string_ok() -> Result<()> {
|
||||||
let fx_sample_config_string = "
|
let fx_sample_config_string = include_str!("../test_data/sample_config.toml");
|
||||||
[all]
|
let fx_expected_struct = gen_expected_struct();
|
||||||
gitea_url = \"http://localhost:3000\"
|
|
||||||
token = \"fake-token\"
|
|
||||||
|
|
||||||
[\"/home/robert/projects/gt-tool\"]
|
|
||||||
owner = \"robert\"
|
|
||||||
repo = \"gt-tool\"
|
|
||||||
|
|
||||||
[\"/home/robert/projects/rcalc\"]
|
|
||||||
owner = \"jamis\"
|
|
||||||
repo = \"rcalc\"
|
|
||||||
|
|
||||||
[\"/home/robert/projects/rcalc-builders\"]
|
|
||||||
owner = \"jamis\"
|
|
||||||
repo = \"rcalc\"
|
|
||||||
";
|
|
||||||
let fx_expected_struct = WholeFile {
|
|
||||||
all: PartialConfig {
|
|
||||||
project_path: None,
|
|
||||||
gitea_url: Some(String::from("http://localhost:3000")),
|
|
||||||
owner: None,
|
|
||||||
repo: None,
|
|
||||||
token: Some(String::from("fake-token"))
|
|
||||||
},
|
|
||||||
project_overrides: vec![
|
|
||||||
PartialConfig {
|
|
||||||
project_path: Some(String::from("/home/robert/projects/gt-tool")),
|
|
||||||
gitea_url: None,
|
|
||||||
owner: Some(String::from("robert")),
|
|
||||||
repo: Some(String::from("gt-tool")),
|
|
||||||
token: None,
|
|
||||||
},
|
|
||||||
PartialConfig {
|
|
||||||
project_path: Some(String::from("/home/robert/projects/rcalc")),
|
|
||||||
gitea_url: None,
|
|
||||||
owner: Some(String::from("jamis")),
|
|
||||||
repo: Some(String::from("rcalc")),
|
|
||||||
token: None,
|
|
||||||
},
|
|
||||||
PartialConfig {
|
|
||||||
project_path: Some(String::from("/home/robert/projects/rcalc-builders")),
|
|
||||||
gitea_url: None,
|
|
||||||
owner: Some(String::from("jamis")),
|
|
||||||
repo: Some(String::from("rcalc")),
|
|
||||||
token: None,
|
|
||||||
},
|
|
||||||
|
|
||||||
],
|
|
||||||
};
|
|
||||||
let conf = read_conf_str(fx_sample_config_string)?;
|
let conf = read_conf_str(fx_sample_config_string)?;
|
||||||
println!(" ->> Test conf: {:?}", conf);
|
println!(" ->> Test conf: {:?}", conf);
|
||||||
println!(" ->> Ref conf: {:?}", fx_expected_struct);
|
println!(" ->> Ref conf: {:?}", fx_expected_struct);
|
||||||
|
|||||||
15
test_data/sample_config.toml
Normal file
15
test_data/sample_config.toml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[all]
|
||||||
|
gitea_url = "http://localhost:3000"
|
||||||
|
token = "fake-token"
|
||||||
|
|
||||||
|
["/home/robert/projects/gt-tool"]
|
||||||
|
owner = "robert"
|
||||||
|
repo = "gt-tool"
|
||||||
|
|
||||||
|
["/home/robert/projects/rcalc"]
|
||||||
|
owner = "jamis"
|
||||||
|
repo = "rcalc"
|
||||||
|
|
||||||
|
["/home/robert/projects/rcalc-builders"]
|
||||||
|
owner = "jamis"
|
||||||
|
repo = "rcalc"
|
||||||
Reference in New Issue
Block a user