From 1e356401bd16d828fbfdc95d13ec22b3d48138e0 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Wed, 20 Sep 2023 18:50:28 +1200 Subject: [PATCH] Verify that the set_ports() method works. This can be flakey, because we're working with sets but then asserting that things happen in a specific order. That should get resolved. --- test/test_model.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_model.py b/test/test_model.py index d33cdc2a0..60eaff862 100755 --- a/test/test_model.py +++ b/test/test_model.py @@ -3406,6 +3406,30 @@ def test_opened_ports_warnings(self): ['opened-ports', ''], ]) + def test_set_ports(self): + fake_script(self, 'open-port', 'exit 0') + fake_script(self, 'close-port', 'exit 0') + fake_script(self, 'opened-ports', 'exit 0') + self.unit.set_ports(8000, 8025) + self.assertEqual(fake_script_calls(self, clear=True), [ + ['opened-ports', ''], + ['open-port', '8025/tcp'], + ['open-port', '8000/tcp'], + ]) + fake_script(self, 'opened-ports', 'echo 8025/tcp') + self.unit.set_ports(ops.Port('udp', 8022)) + self.assertEqual(fake_script_calls(self, clear=True), [ + ['opened-ports', ''], + ['close-port', '8025/tcp'], + ['open-port', '8022/udp'], + ]) + fake_script(self, 'opened-ports', 'echo 8022/udp') + self.unit.set_ports() + self.assertEqual(fake_script_calls(self, clear=True), [ + ['opened-ports', ''], + ['close-port', '8022/udp'], + ]) + if __name__ == "__main__": unittest.main()