forked from kemitix/git-next
refactor(config): rename Config as ServerConfig
This commit is contained in:
parent
a4e781d4e4
commit
d5e9b14e3d
2 changed files with 6 additions and 5 deletions
|
@ -7,11 +7,12 @@ use serde::Deserialize;
|
||||||
use terrors::OneOf;
|
use terrors::OneOf;
|
||||||
|
|
||||||
use crate::filesystem::FileSystem;
|
use crate::filesystem::FileSystem;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Deserialize)]
|
||||||
pub struct Config {
|
pub struct ServerConfig {
|
||||||
forge: HashMap<String, Forge>,
|
forge: HashMap<String, Forge>,
|
||||||
}
|
}
|
||||||
impl Config {
|
impl ServerConfig {
|
||||||
pub(crate) fn load(fs: &FileSystem) -> Result<Self, OneOf<(std::io::Error, toml::de::Error)>> {
|
pub(crate) fn load(fs: &FileSystem) -> Result<Self, OneOf<(std::io::Error, toml::de::Error)>> {
|
||||||
let str = fs.read_file("git-next-server.toml").map_err(OneOf::new)?;
|
let str = fs.read_file("git-next-server.toml").map_err(OneOf::new)?;
|
||||||
toml::from_str(&str).map_err(OneOf::new)
|
toml::from_str(&str).map_err(OneOf::new)
|
||||||
|
@ -209,7 +210,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_config_load() -> Result<(), OneOf<(std::io::Error, toml::de::Error)>> {
|
fn test_server_config_load() -> Result<(), OneOf<(std::io::Error, toml::de::Error)>> {
|
||||||
let fs = FileSystem::new_temp().map_err(OneOf::new)?;
|
let fs = FileSystem::new_temp().map_err(OneOf::new)?;
|
||||||
fs.write_file(
|
fs.write_file(
|
||||||
"git-next-server.toml",
|
"git-next-server.toml",
|
||||||
|
@ -225,7 +226,7 @@ mod tests {
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.map_err(OneOf::new)?;
|
.map_err(OneOf::new)?;
|
||||||
let config = Config::load(&fs)?;
|
let config = ServerConfig::load(&fs)?;
|
||||||
let_assert!(Some(default) = config.forge.get("default"));
|
let_assert!(Some(default) = config.forge.get("default"));
|
||||||
assert_eq!(default.forge_type, ForgeType::ForgeJo);
|
assert_eq!(default.forge_type, ForgeType::ForgeJo);
|
||||||
assert_eq!(default.hostname, "git.example.net".to_string());
|
assert_eq!(default.hostname, "git.example.net".to_string());
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub fn start(fs: FileSystem) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
info!("Starting Server...");
|
info!("Starting Server...");
|
||||||
let config = match config::Config::load(&fs) {
|
let config = match config::ServerConfig::load(&fs) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to load config file. Error: {}", err);
|
error!("Failed to load config file. Error: {}", err);
|
||||||
|
|
Loading…
Reference in a new issue