Remove the hard-coded hab user in the tests
@@ -661,6 +661,7 @@ fn ensure_directory_structure(root: &Path, file: &Path, user: &str, group: &str)
fn write_templated_file(path: &Path, compiled: &str, user: &str, group: &str) -> Result<()> {
File::create(path).and_then(|mut file| file.write_all(compiled.as_bytes()))?;
+
set_permissions(&path, &user, &group)?;
Ok(())
}
@@ -670,7 +671,10 @@ mod test {
use super::*;
use crate::{
error::Error,
- hcore::package::{PackageIdent, PackageInstall},
+ hcore::{
+ os::users,
+ package::{PackageIdent, PackageInstall},
+ },
templating::{context::RenderContext, test_helpers::*},
};
use std::{
@@ -680,8 +684,13 @@ mod test {
use tempfile::TempDir;
use toml;
- const USER: &str = "hab";
- const GROUP: &str = "hab";
+ fn curr_username() -> String {
+ users::get_current_username().expect("Can get current username")
+ }
+
+ fn curr_groupname() -> String {
+ users::get_current_groupname().expect("Can get current groupname")
+ }
fn toml_from_str(content: &str) -> toml::value::Table {
toml::from_str(content)
@@ -1121,7 +1130,8 @@ mod test {
let contents = "foo\nbar\n";
assert_eq!(file.exists(), false);
- write_templated_file(&file, &contents, &USER, &GROUP).expect("writes file");
+ write_templated_file(&file, &contents, &curr_username(), &curr_groupname())
+ .expect("writes file");
assert!(file.exists());
}
@@ -1136,16 +1146,16 @@ mod test {
assert_eq!(file.exists(), false);
- ensure_directory_structure(&template_dir, &file, &USER, &GROUP)
+ ensure_directory_structure(&template_dir, &file, &curr_username(), &curr_groupname())
.expect("create output dir structure");
- write_templated_file(&file, &contents, &USER, &GROUP).expect("writes file");
+ write_templated_file(&file, &contents, &curr_username(), &curr_groupname())
+ .expect("writes file");
assert!(file.exists());
assert_eq!(file_content(file), contents);
}
#[test]
#[cfg(unix)]
- #[should_panic(expected = "Permission denied")]
fn write_template_file_no_perms() {
use crate::hcore::util::posix_perm;
const NO_PERMISSIONS: u32 = 0o000;
@@ -1159,7 +1169,9 @@ mod test {
let contents = "foo\nbar\n";
assert_eq!(file.exists(), false);
- write_templated_file(&file, &contents, &USER, &GROUP).expect("should fail on permissions");
+ assert!(
+ write_templated_file(&file, &contents, &curr_username(), &curr_groupname()).is_err()
+ );
}
#[test]
