Skip to content

Commit 9465ff1

Browse files
committed
refactor(tests): split integration tests into separate files
- Move from single 700-line file to modular structure - Create tests/integration/ directory with 8 separate files: - test_state_integration.py (3 tests) - test_sslcert_integration.py (3 tests) - test_ntp_integration.py (2 tests) - test_license_integration.py (1 test) - test_threshold_integration.py (6 tests - above/below) - test_nsconfig_integration.py (1 test) - test_hwinfo_integration.py (1 test) - test_debug_integration.py (1 test) - Remove old test_integration_with_mock_api.py Total: 18 integration tests, all passing. Benefits: - Better organization (one file per command group) - Easier to navigate and maintain - Follows pytest best practices
1 parent 133edf8 commit 9465ff1

10 files changed

Lines changed: 537 additions & 576 deletions

tests/integration/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Integration tests using Mock NITRO API Server"""
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Integration tests for Debug Command"""
2+
3+
from argparse import Namespace
4+
5+
from check_netscaler.client import NITROClient
6+
from check_netscaler.commands.debug import DebugCommand
7+
from check_netscaler.constants import STATE_OK
8+
9+
10+
class TestDebugCommandIntegration:
11+
"""Test debug command against mock API"""
12+
13+
def test_debug_raw_response(self, mock_nitro_server):
14+
"""Test debug shows raw API response"""
15+
with NITROClient(
16+
hostname=mock_nitro_server.host,
17+
port=mock_nitro_server.port,
18+
username="nsroot",
19+
password="nsroot",
20+
ssl=False,
21+
) as client:
22+
args = Namespace(
23+
command="debug",
24+
objecttype="lbvserver",
25+
objectname="lb_web",
26+
endpoint="config",
27+
)
28+
29+
command = DebugCommand(client, args)
30+
result = command.execute()
31+
32+
assert result.status == STATE_OK
33+
assert "lbvserver" in result.message or "lb_web" in result.message
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Integration tests for HWInfo Command"""
2+
3+
from argparse import Namespace
4+
5+
from check_netscaler.client import NITROClient
6+
from check_netscaler.commands.hwinfo import HWInfoCommand
7+
from check_netscaler.constants import STATE_OK
8+
9+
10+
class TestHWInfoCommandIntegration:
11+
"""Test hwinfo command against mock API"""
12+
13+
def test_hwinfo_display(self, mock_nitro_server):
14+
"""Test hwinfo displays hardware information"""
15+
with NITROClient(
16+
hostname=mock_nitro_server.host,
17+
port=mock_nitro_server.port,
18+
username="nsroot",
19+
password="nsroot",
20+
ssl=False,
21+
) as client:
22+
args = Namespace(command="hwinfo")
23+
24+
command = HWInfoCommand(client, args)
25+
result = command.execute()
26+
27+
assert result.status == STATE_OK
28+
assert "Platform" in result.message or "CPU" in result.message
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Integration tests for License Command"""
2+
3+
from argparse import Namespace
4+
5+
from check_netscaler.client import NITROClient
6+
from check_netscaler.commands.license import LicenseCommand
7+
from check_netscaler.constants import STATE_OK
8+
9+
10+
class TestLicenseCommandIntegration:
11+
"""Test license command against mock API"""
12+
13+
def test_license_check_ok(self, mock_nitro_server):
14+
"""Test license check with valid license"""
15+
with NITROClient(
16+
hostname=mock_nitro_server.host,
17+
port=mock_nitro_server.port,
18+
username="nsroot",
19+
password="nsroot",
20+
ssl=False,
21+
) as client:
22+
args = Namespace(
23+
command="license",
24+
objectname=None,
25+
warning="30",
26+
critical="10",
27+
endpoint="config",
28+
)
29+
30+
command = LicenseCommand(client, args)
31+
result = command.execute()
32+
33+
assert result.status == STATE_OK
34+
assert "CNS_V3000_SERVER_PLT" in result.message
35+
assert "CNS_WEBLOGGING" in result.message
36+
assert "CNS_SSL" in result.message
37+
assert "never expires" in result.message
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Integration tests for NSConfig Command"""
2+
3+
from argparse import Namespace
4+
5+
from check_netscaler.client import NITROClient
6+
from check_netscaler.commands.nsconfig import NSConfigCommand
7+
from check_netscaler.constants import STATE_OK
8+
9+
10+
class TestNSConfigCommandIntegration:
11+
"""Test nsconfig command against mock API"""
12+
13+
def test_nsconfig_no_changes(self, mock_nitro_server):
14+
"""Test nsconfig when no unsaved changes"""
15+
with NITROClient(
16+
hostname=mock_nitro_server.host,
17+
port=mock_nitro_server.port,
18+
username="nsroot",
19+
password="nsroot",
20+
ssl=False,
21+
) as client:
22+
args = Namespace(command="nsconfig")
23+
24+
command = NSConfigCommand(client, args)
25+
result = command.execute()
26+
27+
assert result.status == STATE_OK
28+
assert "No unsaved configuration changes" in result.message
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""Integration tests for NTP Command"""
2+
3+
from argparse import Namespace
4+
5+
from check_netscaler.client import NITROClient
6+
from check_netscaler.commands.ntp import NTPCommand
7+
from check_netscaler.constants import STATE_OK, STATE_WARNING
8+
9+
10+
class TestNTPCommandIntegration:
11+
"""Test NTP command against mock API"""
12+
13+
def test_ntp_check_ok(self, mock_nitro_server):
14+
"""Test NTP check with synchronized state"""
15+
with NITROClient(
16+
hostname=mock_nitro_server.host,
17+
port=mock_nitro_server.port,
18+
username="nsroot",
19+
password="nsroot",
20+
ssl=False,
21+
) as client:
22+
args = Namespace(
23+
command="ntp",
24+
warning=None,
25+
critical=None,
26+
)
27+
28+
command = NTPCommand(client, args)
29+
result = command.execute()
30+
31+
assert result.status == STATE_OK
32+
assert "Offset" in result.message
33+
assert "jitter" in result.message
34+
assert "stratum" in result.message
35+
assert "truechimers=3" in result.message
36+
assert "offset" in result.perfdata
37+
assert "jitter" in result.perfdata
38+
assert result.perfdata["truechimers"] == 3.0
39+
40+
def test_ntp_check_with_thresholds(self, mock_nitro_server):
41+
"""Test NTP check with warning thresholds"""
42+
with NITROClient(
43+
hostname=mock_nitro_server.host,
44+
port=mock_nitro_server.port,
45+
username="nsroot",
46+
password="nsroot",
47+
ssl=False,
48+
) as client:
49+
# Set warning at 0.003s (3ms) - our fixture has 5ms offset
50+
args = Namespace(
51+
command="ntp",
52+
warning="o=0.003",
53+
critical="o=0.010",
54+
)
55+
56+
command = NTPCommand(client, args)
57+
result = command.execute()
58+
59+
assert result.status == STATE_WARNING
60+
assert "WARNING" in result.message
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"""Integration tests for SSL Certificate Command"""
2+
3+
from argparse import Namespace
4+
5+
from check_netscaler.client import NITROClient
6+
from check_netscaler.commands.sslcert import SSLCertCommand
7+
from check_netscaler.constants import STATE_CRITICAL, STATE_OK, STATE_WARNING
8+
9+
10+
class TestSSLCertCommandIntegration:
11+
"""Test SSL certificate command against mock API"""
12+
13+
def test_sslcert_check_ok(self, mock_nitro_server):
14+
"""Test SSL cert check with OK cert (60 days)"""
15+
with NITROClient(
16+
hostname=mock_nitro_server.host,
17+
port=mock_nitro_server.port,
18+
username="nsroot",
19+
password="nsroot",
20+
ssl=False,
21+
) as client:
22+
args = Namespace(
23+
command="sslcert",
24+
objecttype="sslcertkey",
25+
objectname="cert_web",
26+
warning="30",
27+
critical="10",
28+
filter=None,
29+
limit=None,
30+
)
31+
32+
command = SSLCertCommand(client, args)
33+
result = command.execute()
34+
35+
assert result.status == STATE_OK
36+
assert "1 certificate(s) OK" in result.message
37+
assert "warn=30d" in result.message
38+
assert "crit=10d" in result.message
39+
40+
def test_sslcert_check_warning(self, mock_nitro_server):
41+
"""Test SSL cert check with warning cert (20 days)"""
42+
with NITROClient(
43+
hostname=mock_nitro_server.host,
44+
port=mock_nitro_server.port,
45+
username="nsroot",
46+
password="nsroot",
47+
ssl=False,
48+
) as client:
49+
args = Namespace(
50+
command="sslcert",
51+
objecttype="sslcertkey",
52+
objectname="cert_warning",
53+
warning="30",
54+
critical="10",
55+
filter=None,
56+
limit=None,
57+
)
58+
59+
command = SSLCertCommand(client, args)
60+
result = command.execute()
61+
62+
assert result.status == STATE_WARNING
63+
assert "WARNING:" in result.message
64+
assert "cert_warning expires in 20 days" in result.message
65+
66+
def test_sslcert_check_critical(self, mock_nitro_server):
67+
"""Test SSL cert check with critical cert (5 days)"""
68+
with NITROClient(
69+
hostname=mock_nitro_server.host,
70+
port=mock_nitro_server.port,
71+
username="nsroot",
72+
password="nsroot",
73+
ssl=False,
74+
) as client:
75+
args = Namespace(
76+
command="sslcert",
77+
objecttype="sslcertkey",
78+
objectname="cert_critical",
79+
warning="30",
80+
critical="10",
81+
filter=None,
82+
limit=None,
83+
)
84+
85+
command = SSLCertCommand(client, args)
86+
result = command.execute()
87+
88+
assert result.status == STATE_CRITICAL
89+
assert "CRITICAL:" in result.message
90+
assert "cert_critical expires in 5 days" in result.message
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""Integration tests for State Command"""
2+
3+
from argparse import Namespace
4+
5+
from check_netscaler.client import NITROClient
6+
from check_netscaler.commands.state import StateCommand
7+
from check_netscaler.constants import STATE_CRITICAL, STATE_OK
8+
9+
10+
class TestStateCommandIntegration:
11+
"""Test state command against mock API"""
12+
13+
def test_state_check_lbvserver_up(self, mock_nitro_server):
14+
"""Test checking state of UP load balancer"""
15+
with NITROClient(
16+
hostname=mock_nitro_server.host,
17+
port=mock_nitro_server.port,
18+
username="nsroot",
19+
password="nsroot",
20+
ssl=False,
21+
) as client:
22+
args = Namespace(
23+
command="state",
24+
objecttype="lbvserver",
25+
objectname="lb_web",
26+
filter=None,
27+
limit=None,
28+
)
29+
30+
command = StateCommand(client, args)
31+
result = command.execute()
32+
33+
assert result.status == STATE_OK
34+
assert result.message == "lbvserver is UP"
35+
36+
def test_state_check_lbvserver_down(self, mock_nitro_server):
37+
"""Test checking state of DOWN load balancer"""
38+
with NITROClient(
39+
hostname=mock_nitro_server.host,
40+
port=mock_nitro_server.port,
41+
username="nsroot",
42+
password="nsroot",
43+
ssl=False,
44+
) as client:
45+
args = Namespace(
46+
command="state",
47+
objecttype="lbvserver",
48+
objectname="lb_down",
49+
filter=None,
50+
limit=None,
51+
)
52+
53+
command = StateCommand(client, args)
54+
result = command.execute()
55+
56+
assert result.status == STATE_CRITICAL
57+
assert "CRITICAL" in result.message
58+
assert "lb_down" in result.message
59+
assert "1/1" in result.message
60+
61+
def test_state_check_all_lbvservers(self, mock_nitro_server):
62+
"""Test checking all load balancers"""
63+
with NITROClient(
64+
hostname=mock_nitro_server.host,
65+
port=mock_nitro_server.port,
66+
username="nsroot",
67+
password="nsroot",
68+
ssl=False,
69+
) as client:
70+
args = Namespace(
71+
command="state",
72+
objecttype="lbvserver",
73+
objectname=None,
74+
filter=None,
75+
limit=None,
76+
)
77+
78+
command = StateCommand(client, args)
79+
result = command.execute()
80+
81+
assert result.status == STATE_CRITICAL
82+
assert "CRITICAL" in result.message
83+
assert "lb_down" in result.message
84+
assert "1/3" in result.message

0 commit comments

Comments
 (0)