Skip to content

Commit

Permalink
Remove manual test.
Browse files Browse the repository at this point in the history
Add automated tests.
  • Loading branch information
Ealdwulf authored and radujipa committed Mar 15, 2018
1 parent 8926a63 commit ef9715d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
docopt
pyyaml
64 changes: 64 additions & 0 deletions tests/test_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# test_monitor.py
#
# Copyright (C) 2018 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Tests for the `kano_updater.monitor` module
#


import pytest


def run_monitor(mon_timeout, test_cmd):
import kano_updater.monitor
kano_updater.monitor.MONITOR_TIMEOUT = mon_timeout
rc = kano_updater.monitor.run(test_cmd)

return rc


def test_return_code():
import os
import random
# When command returns in time,
# Then rc should be the command's rc
expected_rc = random.randint(1, 20)
rc = run_monitor(10, ["./tests/monitor_stub.py", "5", str(expected_rc)])
assert rc == expected_rc


def test_return_timeout():
import os
import random
import kano_updater.return_codes
# When command returns in time,
# Then rc should be HANGED_INDEFINITELY
command_rc = random.randint(1, 20)
rc = run_monitor(5, ["./tests/monitor_stub.py", "10", str(command_rc)])
assert rc == kano_updater.return_codes.RC.HANGED_INDEFINITELY


def test_forking():
import os
import random
# When command takes longer than timeout but forks,
# Then rc should be the command's rc
expected_rc = random.randint(1, 20)
rc = run_monitor(5, ["./tests/monitor_stub.py", "--forking", "10", str(expected_rc)])
assert rc == expected_rc


def test_signal():
import os
import random
# When command takes longer than timeout but signals,
# Then rc should be the command's rc
expected_rc = random.randint(1, 20)
rc = run_monitor(5, ["./tests/monitor_stub.py", "--signal", "10", str(expected_rc)])
assert rc == expected_rc


# TBD:
# - test gui mode

0 comments on commit ef9715d

Please sign in to comment.