diff options
| author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2026-08-22 01:36:21 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-21 10:36:21 -0500 |
| commit | 7a6b5e4f3a7a021cfa75faa7bf833741dfc09cff (patch) | |
| tree | 82dad9c7ca58b7c88ac25f2ef7b04413e259a260 /tests/unit/modules/test_vyos_facts.py | |
| parent | cb738721c15ac01f49f66144dae80eb478331f77 (diff) | |
| download | rest.vyos-7a6b5e4f3a7a021cfa75faa7bf833741dfc09cff.tar.gz rest.vyos-7a6b5e4f3a7a021cfa75faa7bf833741dfc09cff.zip | |
T8989: wave3 user, bgp_global, bgp_address_family, facts, firewall_global
* T8989: vyos_user module
* T8989: Wave 3 vyos_user module with integration and unit tests
* T8989: Wave 3 vyos_bgp_global module with integration and unit tests
* T8989: Wave 3 vyos_bgp_address_family module with integration and unit tests
* T8989: Add overridden integration tests for vyos_bgp_global and vyos_bgp_address_family
* T8989: vyos_facts
* T8989: Add vyos_facts integration and unit tests with fixtures
* T8989: vyos_firewall_global module
* T8989: vyos_firewall_global module with integration and unit tests
* T8989: vyos_firewall_rules module
* T8989: vyos_firewall_rules module with integration and unit tests
* T8989: vyos_firewall_interfaces module
* T8989: vyos_firewall_interfaces module
* T8989: vyos_firewall_interfaces UAT & SIT
* T8989: vyos_firewall_interfaces UAT & SIT
Diffstat (limited to 'tests/unit/modules/test_vyos_facts.py')
| -rw-r--r-- | tests/unit/modules/test_vyos_facts.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/unit/modules/test_vyos_facts.py b/tests/unit/modules/test_vyos_facts.py new file mode 100644 index 0000000..3fcf82e --- /dev/null +++ b/tests/unit/modules/test_vyos_facts.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +import json +import os +import unittest + +from unittest.mock import MagicMock + +from ansible_collections.vyos.rest.plugins.modules.vyos_facts import ( + gather_bgp, + gather_hostname, + gather_interfaces, + gather_logging, + gather_users, +) + + +def load_fixture(filename): + fixtures_dir = os.path.join(os.path.dirname(__file__), "..", "fixtures") + with open(os.path.join(fixtures_dir, filename)) as f: + return json.load(f) + + +class TestVyOSFactsGather(unittest.TestCase): + + def setUp(self): + self.mock_vyos = MagicMock() + self.system_fixture = load_fixture("facts_system.json") + self.interfaces_fixture = load_fixture("facts_interfaces.json") + + def test_gather_hostname(self): + self.mock_vyos.get_config = MagicMock(return_value=self.system_fixture) + result = gather_hostname(self.mock_vyos) + self.assertEqual(result, "vyos-test") + + def test_gather_hostname_empty(self): + self.mock_vyos.get_config = MagicMock(return_value={}) + result = gather_hostname(self.mock_vyos) + self.assertEqual(result, "") + + def test_gather_interfaces(self): + self.mock_vyos.get_config = MagicMock(return_value=self.interfaces_fixture) + result = gather_interfaces(self.mock_vyos) + self.assertIn("ethernet", result) + self.assertIn("eth0", result["ethernet"]) + self.assertIn("eth1", result["ethernet"]) + self.assertEqual(result["ethernet"]["eth1"]["description"], "uplink") + + def test_gather_users(self): + self.mock_vyos.get_config = MagicMock( + return_value=self.system_fixture["login"], + ) + result = gather_users(self.mock_vyos) + names = [u["name"] for u in result] + self.assertIn("vyos", names) + self.assertIn("alice", names) + alice = next(u for u in result if u["name"] == "alice") + self.assertEqual(alice["full_name"], "Alice Smith") + self.assertIn("alice-key", alice["public_keys"]) + + def test_gather_users_empty(self): + self.mock_vyos.get_config = MagicMock(return_value={}) + result = gather_users(self.mock_vyos) + self.assertEqual(result, []) + + def test_gather_users_none(self): + self.mock_vyos.get_config = MagicMock(return_value=None) + result = gather_users(self.mock_vyos) + self.assertEqual(result, []) + + def test_gather_bgp(self): + data = {"system-as": "65000", "parameters": {"router-id": "192.0.1.1"}} + self.mock_vyos.get_config = MagicMock(return_value=data) + result = gather_bgp(self.mock_vyos) + self.assertEqual(result["system-as"], "65000") + self.assertEqual(result["parameters"]["router-id"], "192.0.1.1") + + def test_gather_bgp_empty(self): + self.mock_vyos.get_config = MagicMock(return_value={}) + result = gather_bgp(self.mock_vyos) + self.assertEqual(result, {}) + + def test_gather_logging(self): + self.mock_vyos.get_config = MagicMock( + return_value=self.system_fixture["syslog"], + ) + result = gather_logging(self.mock_vyos) + self.assertIn("local", result) + self.assertIn("console", result) + + +if __name__ == "__main__": + unittest.main() |
