mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 21:24:36 +00:00
agent: config: Implement Default
A single constructor setting default value is a typical pattern for a Default implementation. Signed-off-by: Samuel Ortiz <samuel.e.ortiz@protonmail.com>
This commit is contained in:
parent
10ec4b133c
commit
b888edc2fc
@ -91,8 +91,8 @@ macro_rules! parse_cmdline_param {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AgentConfig {
|
impl Default for AgentConfig {
|
||||||
pub fn new() -> AgentConfig {
|
fn default() -> Self {
|
||||||
AgentConfig {
|
AgentConfig {
|
||||||
debug_console: false,
|
debug_console: false,
|
||||||
dev_mode: false,
|
dev_mode: false,
|
||||||
@ -106,7 +106,9 @@ impl AgentConfig {
|
|||||||
tracing: tracer::TraceType::Disabled,
|
tracing: tracer::TraceType::Disabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AgentConfig {
|
||||||
#[instrument]
|
#[instrument]
|
||||||
pub fn parse_cmdline(&mut self, file: &str) -> Result<()> {
|
pub fn parse_cmdline(&mut self, file: &str) -> Result<()> {
|
||||||
let cmdline = fs::read_to_string(file)?;
|
let cmdline = fs::read_to_string(file)?;
|
||||||
@ -371,7 +373,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new() {
|
fn test_new() {
|
||||||
let config = AgentConfig::new();
|
let config: AgentConfig = Default::default();
|
||||||
assert!(!config.debug_console);
|
assert!(!config.debug_console);
|
||||||
assert!(!config.dev_mode);
|
assert!(!config.dev_mode);
|
||||||
assert_eq!(config.log_level, DEFAULT_LOG_LEVEL);
|
assert_eq!(config.log_level, DEFAULT_LOG_LEVEL);
|
||||||
@ -721,7 +723,7 @@ mod tests {
|
|||||||
|
|
||||||
let filename = file_path.to_str().expect("failed to create filename");
|
let filename = file_path.to_str().expect("failed to create filename");
|
||||||
|
|
||||||
let mut config = AgentConfig::new();
|
let mut config: AgentConfig = Default::default();
|
||||||
let result = config.parse_cmdline(&filename.to_owned());
|
let result = config.parse_cmdline(&filename.to_owned());
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
|
|
||||||
|
@ -80,8 +80,7 @@ const NAME: &str = "kata-agent";
|
|||||||
const KERNEL_CMDLINE_FILE: &str = "/proc/cmdline";
|
const KERNEL_CMDLINE_FILE: &str = "/proc/cmdline";
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref AGENT_CONFIG: Arc<RwLock<AgentConfig>> =
|
static ref AGENT_CONFIG: Arc<RwLock<AgentConfig>> = Arc::new(RwLock::new(Default::default()));
|
||||||
Arc::new(RwLock::new(config::AgentConfig::new()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
|
Loading…
Reference in New Issue
Block a user