Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/push_pr_checks_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ jobs:
run: |
cargo install --locked cargo-zigbuild --force

- name: Run workspace tests excluding the agent control package
run: cargo test --workspace --exclude 'newrelic_agent_control' --all-targets
- name: Run workspace tests excluding the agent control crate
run: make -C agent-control test/exclude-agent-control-crate

- name: Run tests agent control lib excluding root-required tests (on-host)
run: make -C agent-control test/onhost
Expand All @@ -286,7 +286,7 @@ jobs:
run: make -C agent-control test/k8s

- name: Run documentation tests
run: cargo test --locked --doc
run: make -C agent-control test/doc

# Test using root can be troublesome to perform as usually the Rust toolchain is installed local to the user.
# To test for root privileges, we can run from a container (disabling the test that fail if running non-root).
Expand Down Expand Up @@ -435,6 +435,10 @@ jobs:
shell: bash
run: make -C agent-control test/onhost

- name: Run tests agent control integration tests excluding root-required tests (on-host)
shell: bash
run: make -C agent-control test/onhost/integration

check-all-green:
name: 🟢 All required checks and tests pass
if: always()
Expand Down
10 changes: 7 additions & 3 deletions agent-control/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ onhost/cargo:
@echo "testing-machine-id" > /tmp/machine-id
$(TEST_FIXTURES) cargo $(CARGO_CMD) $(CARGO_ARGS)

.PHONY: test/doc
test/doc:
cargo $(CARGO_CMD) --locked --doc

.PHONY: test/onhost
test/onhost:
@echo "testing-machine-id" > /tmp/machine-id
Expand All @@ -26,7 +30,9 @@ test/onhost/root/integration:
@echo "testing-machine-id" > /tmp/machine-id
$(TEST_FIXTURES) cargo $(CARGO_CMD) $(PACKAGE_SA) --features=multiple-instances --test integration_tests _as_root -- --ignored --skip no_root --skip k8s

# K8S
.PHONY: test/exclude-agent-control-crate
test/exclude-agent-control-crate:
cargo $(CARGO_CMD) --workspace --exclude 'newrelic_agent_control' --all-targets

.PHONY: test/k8s
test/k8s:
Expand All @@ -35,8 +41,6 @@ test/k8s:
.PHONY: test/k8s/integration
test/k8s/integration: test/k8s/integration-part1 test/k8s/integration-part2



.PHONY: test/k8s/integration-part1
test/k8s/integration-part1:
KUBECONFIG='./tests/k8s/.kubeconfig-dev' minikube update-context
Expand Down
5 changes: 2 additions & 3 deletions agent-control/tests/k8s/scenarios/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(target_family = "unix")]
use crate::common::attributes::{
check_latest_identifying_attributes_match_expected,
check_latest_non_identifying_attributes_match_expected, convert_to_vec_key_value,
Expand All @@ -16,9 +15,9 @@ use newrelic_agent_control::agent_control::defaults::{
OPAMP_SERVICE_NAMESPACE, OPAMP_SERVICE_VERSION, OPAMP_SUBAGENT_CHART_VERSION_ATTRIBUTE_KEY,
PARENT_AGENT_ID_ATTRIBUTE_KEY,
};
use nix::unistd::gethostname;
use opamp_client::opamp::proto::any_value::Value;
use opamp_client::opamp::proto::any_value::Value::BytesValue;
use resource_detection::system::hostname::get_hostname;
use std::time::Duration;
use tempfile::tempdir;

Expand Down Expand Up @@ -82,7 +81,7 @@ agents:
let ac_expected_non_identifying_attributes = convert_to_vec_key_value(Vec::from([
(
HOST_NAME_ATTRIBUTE_KEY,
Value::StringValue(gethostname().unwrap_or_default().into_string().unwrap()),
Value::StringValue(get_hostname().unwrap_or_default()),
),
(
FLEET_ID_ATTRIBUTE_KEY,
Expand Down
1 change: 1 addition & 0 deletions agent-control/tests/on_host/config_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::fs::read_to_string;
use std::path::PathBuf;

// This test is the only one that writes to an actual file in the FS
#[cfg(unix)] // Skipping windows as directory manager is not yet implemented. TODO: adapt when ready
#[test]
fn test_store_remote_no_mocks() {
let tempdir = tempfile::tempdir().unwrap();
Expand Down
2 changes: 2 additions & 0 deletions agent-control/tests/on_host/logging/file_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn build_logging_config(config_path: &Path, log_path: &Path) {
std::fs::write(config_path, config).unwrap();
}

#[cfg(unix)] // TODO: enable it back when root/admin checks are implemented for Windows
#[test]
fn default_log_level_no_root() {
let dir = TempDir::new().unwrap();
Expand Down Expand Up @@ -57,6 +58,7 @@ fn default_log_level_no_root() {
}
}

#[cfg(unix)] // TODO: enable it back when root/admin checks are implemented for Windows
#[test]
#[ignore = "requires root"]
fn default_log_level_as_root() {
Expand Down
4 changes: 4 additions & 0 deletions agent-control/tests/on_host/logging/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const TRACE_LEVEL_CONFIG: &str = "agents: {}\nlog:\n level: trace";

pub(crate) const TIME_FORMAT: &str = r".*(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}).*";

#[cfg(unix)] // TODO: enable it back when root/admin checks and directory manager are implemented for Windows
#[test]
fn default_log_level_no_root() {
let dir = TempDir::new().unwrap();
Expand All @@ -33,6 +34,7 @@ fn default_log_level_no_root() {
);
}

#[cfg(unix)] // TODO: enable it back when root/admin checks and directory manager are implemented for Windows
#[test]
#[ignore = "requires root"]
fn default_log_level_as_root() {
Expand Down Expand Up @@ -63,6 +65,7 @@ fn default_log_level_as_root() {
);
}

#[cfg(unix)] // TODO: enable it back when root/admin checks and directory manager are implemented for Windows
#[test]
fn debug_log_level_no_root() {
let dir = TempDir::new().unwrap();
Expand All @@ -88,6 +91,7 @@ fn debug_log_level_no_root() {
);
}

#[cfg(unix)] // TODO: enable it back when root/admin checks and directory manager are implemented for Windows
#[test]
#[ignore = "requires root"]
fn trace_log_level_as_root() {
Expand Down
7 changes: 3 additions & 4 deletions agent-control/tests/on_host/scenarios/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(target_family = "unix")]
use crate::common::agent_control::start_agent_control_with_custom_config;
use crate::common::attributes::{
check_latest_identifying_attributes_match_expected,
Expand All @@ -16,9 +15,9 @@ use newrelic_agent_control::agent_control::defaults::{
PARENT_AGENT_ID_ATTRIBUTE_KEY,
};
use newrelic_agent_control::agent_control::run::{BasePaths, Environment};
use nix::unistd::gethostname;
use opamp_client::opamp::proto::any_value::Value;
use opamp_client::opamp::proto::any_value::Value::BytesValue;
use resource_detection::system::hostname::get_hostname;
use rstest::rstest;
use std::path::PathBuf;
use std::time::Duration;
Expand Down Expand Up @@ -84,7 +83,7 @@ fn test_attributes_from_non_existing_agent_type() {
let expected_non_identifying_attributes = convert_to_vec_key_value(Vec::from([
(
HOST_NAME_ATTRIBUTE_KEY,
Value::StringValue(gethostname().unwrap_or_default().into_string().unwrap()),
Value::StringValue(get_hostname().unwrap_or_default()),
),
(
PARENT_AGENT_ID_ATTRIBUTE_KEY,
Expand Down Expand Up @@ -178,7 +177,7 @@ agents:
let expected_non_identifying_attributes = convert_to_vec_key_value(Vec::from([
(
HOST_NAME_ATTRIBUTE_KEY,
Value::StringValue(gethostname().unwrap_or_default().into_string().unwrap()),
Value::StringValue(get_hostname().unwrap_or_default()),
),
(
PARENT_AGENT_ID_ATTRIBUTE_KEY,
Expand Down
23 changes: 19 additions & 4 deletions agent-control/tests/on_host/scenarios/filesystem_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::{fs::read_to_string, path::Path, time::Duration};
use std::{
fs::read_to_string,
path::{Path, PathBuf},
time::Duration,
};

use newrelic_agent_control::agent_control::{
defaults::GENERATED_FOLDER_NAME,
Expand All @@ -18,6 +22,7 @@ use crate::{

/// An on-host agent definition that includes filesystem entries should result in the entries being
/// created in the appropriate location under the remote directory.
#[cfg(unix)] // Skipping windows as directory manager is not yet implemented. TODO: adapt when ready
#[test]
fn writes_filesystem_entries() {
let opamp_server = FakeServer::start_new();
Expand All @@ -29,7 +34,10 @@ fn writes_filesystem_entries() {
let expected_file_contents = "Hello, world!";
let agent_id = "test-agent";
let dir_entry = "example-filepath";
let file_path = "randomdir/randomfile.txt";
let file_path = PathBuf::from("randomdir")
.join("randomfile.txt")
.to_string_lossy()
.to_string();

create_file(
format!(
Expand Down Expand Up @@ -91,6 +99,7 @@ deployment:
/// An on-host agent definition that includes filesystem entries should result in the entries being
/// created in the appropriate location under the remote directory and with their contents properly
/// rendered from the defined variables.
#[cfg(unix)] // Skipping windows as directory manager is not yet implemented. TODO: adapt when ready
#[test]
fn complete_render_and_and_write_files_and_dirs() {
let opamp_server = FakeServer::start_new();
Expand All @@ -102,8 +111,14 @@ fn complete_render_and_and_write_files_and_dirs() {
let agent_id = "test-agent";

// Rendered file paths
let yaml_file_path = "randomdir/randomfile.yaml";
let string_file_path = "randomdir-2/some_string.txt";
let yaml_file_path = PathBuf::from("randomdir")
.join("randomfile.yaml")
.to_string_lossy()
.to_string();
let string_file_path = PathBuf::from("randomdir-2")
.join("some-string.txt")
.to_string_lossy()
.to_string();

// Rendered directory paths
let dir_path = "somedir";
Expand Down
Loading