Skip to content

Commit eb64b6d

Browse files
Add integration test for agent (#8094)
1 parent 15dee86 commit eb64b6d

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

tests/suite/test_agent.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from kubernetes.stream import stream
3-
from suite.utils.resources_utils import get_first_pod_name, wait_before_test
3+
from suite.utils.resources_utils import get_file_contents, get_first_pod_name, wait_before_test
44

55

66
@pytest.mark.agentv3
@@ -45,3 +45,49 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro
4545

4646
assert f"Failed to get nginx-agent version: fork/exec /usr/bin/nginx-agent" not in log
4747
assert "nginx-agent version v3" in result_conf
48+
49+
# Test for agent.config file - verify the agent config exists inside the NIC pod
50+
# The expected config that will be asserted against later
51+
expected_config = """#
52+
# /etc/nginx-agent/nginx-agent.conf
53+
#
54+
# Configuration file for NGINX Agent.
55+
#
56+
57+
log:
58+
# set log level (error, warn, info, debug; default "info")
59+
level: info
60+
# set log path. if empty, don't log to file.
61+
path: /var/log/nginx-agent/
62+
63+
allowed_directories:
64+
- /etc/nginx
65+
- /usr/local/etc/nginx
66+
- /usr/share/nginx/modules
67+
- /var/run/nginx
68+
- /var/log/nginx
69+
#
70+
# Command server settings to connect to a management plane server
71+
#
72+
#command:
73+
# server:
74+
# host: "agent.connect.nginx.com"
75+
# port: 443
76+
# auth:
77+
# token: ""
78+
# tls:
79+
# skip_verify: false"""
80+
expected_config = expected_config.strip()
81+
82+
# Get the actual config file content from the pod
83+
config_contents = get_file_contents(
84+
kube_apis.v1, "/etc/nginx-agent/nginx-agent.conf", pod_name, ingress_controller_prerequisites.namespace
85+
)
86+
87+
# Normalize whitespace for comparison - remove trailing spaces from each line
88+
def normalize_config(config_text):
89+
return "\n".join(line.rstrip() for line in config_text.strip().split("\n"))
90+
91+
config_contents_normalized = normalize_config(config_contents)
92+
expected_config_normalized = normalize_config(expected_config)
93+
assert config_contents_normalized == expected_config_normalized

0 commit comments

Comments
 (0)