Debian Codegraph @

src/tests.rs

raw symbols SCIP
1 use super::{getent, Error};
2 use crate::HomeDirExt;
3 use std::path::PathBuf;
4
5 #[test]
6 fn test_root() {
7 #[cfg(target_os = "macos")]
8 const ROOT_DIR: &'static str = "/var/root";
9
10 #[cfg(target_os = "linux")]
11 const ROOT_DIR: &'static str = "/root";
12
13 assert_eq!(getent("root").unwrap(), PathBuf::from(ROOT_DIR));
14 }
15
16 #[test]
17 fn test_expand_root() {
18 #[cfg(target_os = "macos")]
19 const ROOT_DIR: &'static str = "/var/root/foobar";
20
21 #[cfg(target_os = "linux")]
22 const ROOT_DIR: &'static str = "/root/foobar";
23
24 assert_eq!(
25 "~root/foobar".expand_home().unwrap(),
26 PathBuf::from(ROOT_DIR)
27 );
28 }
29
30 #[test]
31 fn test_expand_nonexpansion() {
32 assert_eq!(
33 "/etc/some.conf".expand_home().unwrap(),
34 PathBuf::from("/etc/some.conf")
35 );
36 }
37
38 #[test]
39 fn test_missing() {
40 assert!(matches!(
41 getent("_foobar_").unwrap_err(),
42 Error::MissingEntry
43 ));
44 }