Skip to content

Commit

Permalink
chore: Add tests for config (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikornaselur committed Mar 25, 2024
1 parent 8ba240e commit 6bb836a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/config.rs
Expand Up @@ -57,3 +57,50 @@ pub fn get_config() -> &'static Config {
}
})
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_init_from_env() {
env::set_var("JWT_PUBLIC_KEY_B64", "SGVsbG8hCg==");
env::set_var("PORT", "1234");
env::set_var("HOST", "10.11.12.13");
env::set_var("WORKER_COUNT", "4");

let config = Config::init_from_env().unwrap();

assert_eq!(config.port, 1234);
assert_eq!(config.host, "10.11.12.13");
assert_eq!(config.worker_count, 4);
assert_eq!(config.jwt_public_key, b"Hello!\n".to_vec());
}

#[test]
fn test_init_defaults() {
env::set_var("JWT_PUBLIC_KEY_B64", "SGVsbG8hCg==");

let config = Config::init_from_env().unwrap();

assert_eq!(config.port, DEFAULT_PORT);
assert_eq!(config.host, DEFAULT_HOST);
assert_eq!(config.worker_count, DEFAULT_WORKER_COUNT);
assert_eq!(config.jwt_public_key, b"Hello!\n".to_vec());
}

#[test]
fn test_init_requires_jwt_public_key() {
env::remove_var("JWT_PUBLIC_KEY_B64");

let config = Config::init_from_env();

assert!(config.is_err());
let err = config.unwrap_err();
assert_eq!(err.error_type, NotifluxErrorType::EnvError);
assert_eq!(
err.message,
Some("JWT_PUBLIC_KEY_B64 is not set in env".to_string())
);
}
}
1 change: 1 addition & 0 deletions src/server.rs
Expand Up @@ -39,6 +39,7 @@ impl Actor for Server {

impl Handler<message::Broadcast> for Server {
type Result = ();

fn handle(&mut self, msg: message::Broadcast, _: &mut Context<Self>) {
log::debug!("handling Broadcast: {:?}", msg);

Expand Down

0 comments on commit 6bb836a

Please sign in to comment.