diff --git a/tests/suite/test_agent.py b/tests/suite/test_agent.py index 30e2658a5..5f627fed9 100644 --- a/tests/suite/test_agent.py +++ b/tests/suite/test_agent.py @@ -1,6 +1,6 @@ import pytest from kubernetes.stream import stream -from suite.utils.resources_utils import get_first_pod_name, wait_before_test +from suite.utils.resources_utils import get_file_contents, get_first_pod_name, wait_before_test @pytest.mark.agentv3 @@ -45,3 +45,49 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro assert f"Failed to get nginx-agent version: fork/exec /usr/bin/nginx-agent" not in log assert "nginx-agent version v3" in result_conf + + # Test for agent.config file - verify the agent config exists inside the NIC pod + # The expected config that will be asserted against later + expected_config = """# +# /etc/nginx-agent/nginx-agent.conf +# +# Configuration file for NGINX Agent. +# + +log: + # set log level (error, warn, info, debug; default "info") + level: info + # set log path. if empty, don't log to file. + path: /var/log/nginx-agent/ + +allowed_directories: + - /etc/nginx + - /usr/local/etc/nginx + - /usr/share/nginx/modules + - /var/run/nginx + - /var/log/nginx +# +# Command server settings to connect to a management plane server +# +#command: +# server: +# host: "agent.connect.nginx.com" +# port: 443 +# auth: +# token: "" +# tls: +# skip_verify: false""" + expected_config = expected_config.strip() + + # Get the actual config file content from the pod + config_contents = get_file_contents( + kube_apis.v1, "/etc/nginx-agent/nginx-agent.conf", pod_name, ingress_controller_prerequisites.namespace + ) + + # Normalize whitespace for comparison - remove trailing spaces from each line + def normalize_config(config_text): + return "\n".join(line.rstrip() for line in config_text.strip().split("\n")) + + config_contents_normalized = normalize_config(config_contents) + expected_config_normalized = normalize_config(expected_config) + assert config_contents_normalized == expected_config_normalized