Skip to content

Commit

Permalink
Split tests into separate test methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Sep 25, 2023
1 parent b911855 commit b6c6ba6
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3402,8 +3402,7 @@ def test_opened_ports_warnings(self):
['opened-ports', ''],
])

def test_set_ports(self):
# No existing ports, open new ones.
def test_set_ports_all_open(self):
fake_script(self, 'open-port', 'exit 0')
fake_script(self, 'close-port', 'exit 0')
fake_script(self, 'opened-ports', 'exit 0')
Expand All @@ -3415,15 +3414,22 @@ def test_set_ports(self):
['open-port', '8000/tcp'],
['open-port', '8025/tcp'],
])

def test_set_ports_mixed(self):
# Two open ports, leave one alone and open another one.
fake_script(self, 'open-port', 'exit 0')
fake_script(self, 'close-port', 'exit 0')
fake_script(self, 'opened-ports', 'echo 8025/tcp; echo 8028/tcp')
self.unit.set_ports(ops.Port('udp', 8022), 8028)
self.assertEqual(fake_script_calls(self, clear=True), [
['opened-ports', ''],
['close-port', '8025/tcp'],
['open-port', '8022/udp'],
])
# Completely replace the opened ports.

def test_set_ports_replace(self):
fake_script(self, 'open-port', 'exit 0')
fake_script(self, 'close-port', 'exit 0')
fake_script(self, 'opened-ports', 'echo 8025/tcp; echo 8028/tcp')
self.unit.set_ports(8001, 8002)
calls = fake_script_calls(self, clear=True)
Expand All @@ -3435,14 +3441,20 @@ def test_set_ports(self):
['open-port', '8001/tcp'],
['open-port', '8002/tcp'],
])
# Close everything.

def test_set_ports_close_all(self):
fake_script(self, 'open-port', 'exit 0')
fake_script(self, 'close-port', 'exit 0')
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'],
])
# Opening an already open port is a no-op.

def test_set_ports_noop(self):
fake_script(self, 'open-port', 'exit 0')
fake_script(self, 'close-port', 'exit 0')
fake_script(self, 'opened-ports', 'echo 8000/tcp')
self.unit.set_ports(ops.Port('tcp', 8000))
self.assertEqual(fake_script_calls(self, clear=True), [
Expand Down

0 comments on commit b6c6ba6

Please sign in to comment.