Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
use std::io::Error;
use std::path::Path;
Expand All @@ -12,7 +13,13 @@ pub struct Location {
// access to the "type" and "args" fields) is going to require we
// know how to deserialise into a union type; for example
// https://stackoverflow.com/q/66964692
//
// However, we need to support the 'local' type, which takes no
// arguments, so implement enough here to be able to write one.
pub name: String,
#[serde(rename = "type")]
pub loc_type: String,
pub args: HashMap<String, serde_json::Value>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq)]
Expand Down Expand Up @@ -48,7 +55,12 @@ impl Config {
use_file_store,
require_complete_tree,
};
let location: Vec<Location> = Vec::new();
let local = Location {
name: String::from("local"),
loc_type: String::from("local"),
args: HashMap::new(),
};
let location: Vec<Location> = vec![local];
Ok(Config { core, location })
}
}
Expand Down Expand Up @@ -86,6 +98,9 @@ mod tests {
#[test]
fn can_write_config() {
let cfg = Config::new(None, true, true).unwrap();
assert_eq!(cfg.location.len(), 1);
assert_eq!(cfg.location[0].name, "local");
assert_eq!(cfg.location[0].loc_type, "local");
let tmp = tempfile::TempDir::new().unwrap();
let path = tmp.path();
fs::create_dir_all(path.join(".outpack")).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/bad-example/.outpack/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"name": "another",
"type": "file",
"args": []
"args": {}
}
]
}
4 changes: 2 additions & 2 deletions tests/example/.outpack/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
{
"name": "local",
"type": "local",
"args": []
"args": {}
},
{
"name": "another",
"type": "file",
"args": []
"args": {}
}
]
}
Loading