Use `env_config_int` macro
@@ -7,7 +7,6 @@ use crate::{error::{Error,
use habitat_core::os::process::windows_child::{Child,
ExitStatus};
use habitat_core::{crypto,
- env::Config as EnvConfig,
fs};
use serde::{Serialize,
Serializer};
@@ -26,8 +25,7 @@ use std::{ffi::OsStr,
BufReader},
path::{Path,
PathBuf},
- result,
- str::FromStr};
+ result};
#[cfg(not(windows))]
pub const HOOK_PERMISSIONS: u32 = 0o755;
@@ -431,25 +429,10 @@ impl Serialize for RenderPair {
}
}
-struct HookStandardStreamByteLimit(u64);
-
-impl Default for HookStandardStreamByteLimit {
- fn default() -> Self { Self(1024) }
-}
-
-impl FromStr for HookStandardStreamByteLimit {
- type Err = std::num::ParseIntError;
-
- fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { Ok(Self(s.parse()?)) }
-}
-
-impl Into<u64> for HookStandardStreamByteLimit {
- fn into(self) -> u64 { self.0 }
-}
-
-impl EnvConfig for HookStandardStreamByteLimit {
- const ENVVAR: &'static str = "HOOK_STANDARD_STREAM_BYTE_LIMIT";
-}
+habitat_core::env_config_int!(HookStandardStreamByteLimit,
+ u64,
+ HAB_HOOK_STANDARD_STREAM_BYTE_LIMIT,
+ 1024);
pub struct HookOutput<'a> {
stdout_log_file: &'a Path,
@@ -798,6 +781,9 @@ echo "The message is Hello"
////////////////////////////////////////////////////////////////////////
+ crate::locked_env_var!(HAB_HOOK_STANDARD_STREAM_BYTE_LIMIT,
+ hab_hook_standard_stream_byte_limit);
+
#[test]
#[cfg(not(windows))]
fn hook_output() {
@@ -836,7 +822,8 @@ echo "The message is Hello"
assert_eq!(stderr,
"This is stderr\nThis is stderr line 2\nThis is stderr line 3\n");
- std::env::set_var(HookStandardStreamByteLimit::ENVVAR, "20");
+ let envvar = hab_hook_standard_stream_byte_limit();
+ envvar.set("20");
let stdout = hook_output.stdout_str().expect("to get stdout string");
assert_eq!(stdout, "This is stdout\nThis ");
