Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
agent/minimum: set default value for identity instead of returning error
Browse files Browse the repository at this point in the history
tests: add tests to print minimum and full agent with test config file

Signed-off-by: Allen Bai <abai@redhat.com>
  • Loading branch information
Allen Bai committed Oct 21, 2019
1 parent 6a5e8f1 commit 05db91d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/agent/full/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,3 @@ impl IdentityFull {
}
}
}

#[test]
fn test_print_full() {
println!("{:?}", IdentityFull::new());
}
15 changes: 11 additions & 4 deletions src/agent/minimal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,22 @@ impl IdentityMin {
aleph_version: &str,
metadata: &str,
) -> Fallible<Self> {
let platform = platform::get_platform(cmdline)?;
let original_os_version = os_release::read_original_os_version(aleph_version)?;
let platform = platform::get_platform(cmdline).unwrap_or("".to_string());
let original_os_version =
os_release::read_original_os_version(aleph_version).unwrap_or("".to_string());
#[cfg(not(test))]
let current_os_version = rpm_ostree::booted()?.version;
let current_os_version = rpm_ostree::booted()
.unwrap_or(rpm_ostree::Release {
version: "".to_string(),
checksum: "".to_string(),
})
.version;
#[cfg(test)]
let current_os_version = "30.20190924.dev.0".to_string();
let instance_type: Option<String> = match platform.as_str() {
"aliyun" | "aws" | "azure" | "gcp" | "openstack" => Some(
instance_type::read_instance_type(metadata, platform.as_str())?,
instance_type::read_instance_type(metadata, platform.as_str())
.unwrap_or("".to_string()),
),
_ => None,
};
Expand Down
18 changes: 18 additions & 0 deletions src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ impl Agent {
}
}
}

#[test]
fn test_print_minimal() {
use crate::config::inputs;
use clap::crate_name;

let cfg:inputs::ConfigInput = inputs::ConfigInput::read_configs(vec!["tests/minimal/".to_string()], crate_name!()).unwrap();
println!("{:?}", Agent::new(&cfg.collecting));
}

#[test]
fn test_print_full() {
use crate::config::inputs;
use clap::crate_name;

let cfg:inputs::ConfigInput = inputs::ConfigInput::read_configs(vec!["tests/full/".to_string()], crate_name!()).unwrap();
println!("{:?}", Agent::new(&cfg.collecting));
}
18 changes: 12 additions & 6 deletions src/config/fragments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ pub(crate) struct ReportingFragment {
pub(crate) enabled: Option<bool>,
}

#[cfg(test)]
pub(crate) fn mock_config() -> ConfigFragment {
use std::io::Read;

let fp = std::fs::File::open("tests/minimal/fedora-coreos-pinger/config.d/10-default-enable.toml").unwrap();
let mut bufrd = std::io::BufReader::new(fp);
let mut content = vec![];
bufrd.read_to_end(&mut content).unwrap();
toml::from_slice(&content).unwrap()
}

#[cfg(test)]
mod tests {
use super::*;
use std::io::Read;

#[test]
fn basic_dist_config_default() {
let fp = std::fs::File::open("dist/config.d/10-default-enable.toml").unwrap();
let mut bufrd = std::io::BufReader::new(fp);
let mut content = vec![];
bufrd.read_to_end(&mut content).unwrap();
let cfg: ConfigFragment = toml::from_slice(&content).unwrap();
let cfg: ConfigFragment = mock_config();

let expected = ConfigFragment {
collecting: Some(CollectingFragment {
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod fragments;
pub(crate) mod fragments;

pub(crate) mod inputs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# fedora-coreos-pinger default configuration

[collecting]
# Default collecting.level is `minimal`. May be set to `"minimal"` or `"full"`.
level = "full"

[reporting]
# Required. May be set to `true` or `false`.
enabled = true

0 comments on commit 05db91d

Please sign in to comment.