• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

epazote / epazote / 23081788137

14 Mar 2026 05:53AM UTC coverage: 88.727% (+0.3%) from 88.412%
23081788137

push

github

nbari
3.3.0

162 of 166 new or added lines in 7 files covered. (97.59%)

3282 of 3699 relevant lines covered (88.73%)

57.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.39
/src/cli/dispatch/mod.rs
1
use crate::cli::actions::Action;
2
use std::path::PathBuf;
3

4
#[allow(clippy::unnecessary_wraps, clippy::expect_used)]
5
pub fn handler(matches: &clap::ArgMatches) -> Action {
1✔
6
    Action::Run {
1✔
7
        config: matches
1✔
8
            .get_one::<PathBuf>("config")
1✔
9
            .expect("Config path must be present due to default value")
1✔
10
            .clone(),
1✔
11
        port: matches
1✔
12
            .get_one::<u16>("port")
1✔
13
            .copied()
1✔
14
            .expect("Port must be present due to default value"),
1✔
15
    }
1✔
16
}
1✔
17

18
#[cfg(test)]
19
#[allow(clippy::expect_used, clippy::unwrap_used)]
20
mod tests {
21
    use super::*;
22
    use crate::cli::commands::{new, normalize_env_vars};
23
    use std::{ffi::OsString, io::Write, sync::Mutex};
24

25
    const CONF: &str = r"---
26
services:
27
  test:
28
    url: https://epazote.io
29
    every: 1m
30
    expect:
31
      status: 200
32
";
33

34
    static ENV_LOCK: Mutex<()> = Mutex::new(());
35

36
    struct EnvVarGuard {
37
        name: &'static str,
38
        previous: Option<OsString>,
39
    }
40

41
    impl EnvVarGuard {
42
        fn clear(name: &'static str) -> Self {
4✔
43
            let previous = std::env::var_os(name);
4✔
44
            unsafe {
4✔
45
                std::env::remove_var(name);
4✔
46
            }
4✔
47
            Self { name, previous }
4✔
48
        }
4✔
49
    }
50

51
    impl Drop for EnvVarGuard {
52
        fn drop(&mut self) {
4✔
53
            unsafe {
54
                if let Some(value) = &self.previous {
4✔
NEW
55
                    std::env::set_var(self.name, value);
×
56
                } else {
4✔
57
                    std::env::remove_var(self.name);
4✔
58
                }
4✔
59
            }
60
        }
4✔
61
    }
62

63
    // Helper to create config from YAML
64
    fn create_config() -> tempfile::NamedTempFile {
1✔
65
        let mut tmp_file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
1✔
66
        tmp_file
1✔
67
            .write_all(CONF.as_bytes())
1✔
68
            .expect("Failed to write to temp file");
1✔
69
        tmp_file.flush().expect("Failed to flush temp file");
1✔
70
        tmp_file
1✔
71
    }
1✔
72

73
    #[test]
74
    fn test_handler() {
1✔
75
        let _lock = ENV_LOCK.lock().expect("Failed to lock env");
1✔
76
        let _config_env = EnvVarGuard::clear("EPAZOTE_CONFIG");
1✔
77
        let _port_env = EnvVarGuard::clear("EPAZOTE_PORT");
1✔
78
        let _verbose_env = EnvVarGuard::clear("EPAZOTE_VERBOSE");
1✔
79
        let _json_logs_env = EnvVarGuard::clear("EPAZOTE_JSON_LOGS");
1✔
80
        normalize_env_vars();
1✔
81

82
        let tmp_config = create_config();
1✔
83

84
        let config_path = tmp_config.path().to_path_buf();
1✔
85

86
        let matches = new().try_get_matches_from([
1✔
87
            "epazote",
1✔
88
            "--config",
1✔
89
            config_path.to_str().expect("Invalid path"),
1✔
90
        ]);
1✔
91

92
        assert!(matches.is_ok());
1✔
93

94
        let m = matches.expect("Matches should be present");
1✔
95

96
        assert_eq!(
1✔
97
            m.get_one::<PathBuf>("config")
1✔
98
                .map(|p| p.to_str().expect("Invalid path")),
1✔
99
            Some(config_path.to_str().expect("Invalid path"))
1✔
100
        );
101

102
        assert_eq!(m.get_one::<u16>("port").copied(), Some(9080));
1✔
103

104
        assert_eq!(m.get_one::<u8>("verbose").copied(), Some(0));
1✔
105

106
        let action = handler(&m);
1✔
107

108
        match action {
1✔
109
            Action::Run { config, port } => {
1✔
110
                assert_eq!(config, config_path);
1✔
111
                assert_eq!(port, 9080);
1✔
112
            }
113
        }
114
    }
1✔
115
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc