-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override TOML config from environment variables
- Loading branch information
1 parent
af386d0
commit 4a45847
Showing
2 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,51 @@ | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[derive(Clone, Debug, Default, Deserialize)] | ||
pub struct MqttConfig { | ||
pub host: String, | ||
pub port: Option<u16>, | ||
pub username: Option<String>, | ||
pub password: Option<String>, | ||
} | ||
|
||
impl MqttConfig { | ||
pub fn is_valid(&self) -> bool { | ||
!self.host.is_empty() | ||
} | ||
} | ||
|
||
mod tests { | ||
#[test] | ||
fn valid_config() { | ||
use super::MqttConfig; | ||
|
||
let mqtt_config = MqttConfig { | ||
host: "lala".into(), | ||
port: None, | ||
username: None, | ||
password: None, | ||
}; | ||
assert!(mqtt_config.is_valid()); | ||
} | ||
|
||
#[test] | ||
fn invalid_config() { | ||
use super::MqttConfig; | ||
|
||
let mqtt_config = MqttConfig { | ||
host: "".into(), | ||
port: None, | ||
username: None, | ||
password: None, | ||
}; | ||
assert!(!mqtt_config.is_valid()); | ||
} | ||
|
||
#[test] | ||
fn default_invalid_config() { | ||
use super::MqttConfig; | ||
|
||
let mqtt_config = MqttConfig::default(); | ||
assert!(!mqtt_config.is_valid()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters