diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 6135ec6..bc0d82a 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -46,4 +46,22 @@ jobs: run: | docker run --rm -v ${{ github.workspace }}:/app \ ${{ env.REPOSITORY }}:${{ matrix.distro }}-pytest \ - ${{ steps.setup.outputs.command }} -v tests/test_system.py -p no:cacheprovider + ${{ steps.setup.outputs.command }} -v tests/test_validate_options.py -p no:cacheprovider + + test-systems-with-logs: + # We only want to pull large files once, so lets run this on a single runner + runs-on: ubuntu-latest + strategy: + matrix: + distro: ["amazonlinux"] + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + lfs: true + + - name: Run system tests with logs + run: | + docker run --rm -v ${{ github.workspace }}:/app \ + ${{ env.REPOSITORY }}:${{ matrix.distro }}-pytest \ + pytest -v tests/test_large_log.py -p no:cacheprovider -s diff --git a/tests/test_large_log.py b/tests/test_large_log.py new file mode 100644 index 0000000..99e7c90 --- /dev/null +++ b/tests/test_large_log.py @@ -0,0 +1,50 @@ +import os +import sys +from optparse import Values + +import pytest + +# Add the parent directory to the path so we can import the latest version of the script +oom_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) +sys.path.insert(0, oom_dir) + +from oom_investigate import System, run, validate_options + +# Ignore DeprecationWarning and PendingDeprecationWarning warnings +pytest.mark.filterwarnings("ignore::DeprecationWarning") +pytest.mark.filterwarnings("ignore::PendingDeprecationWarning") + + +class TestSystem: + system = System() + values = Values( + { + "file": False, + "show_counter": 5, + "reverse": False, + "journalctl": False, + "dmesg": False, + "quick": False, + "version": None, + "show_all": False, + } + ) + + def test_file_processing(self, capsys): + # Test specific functionality when '-f messages' is passed + options = self.values + options.file = "tests/assets/logs/messages" + # While we're here, we might as well test the --all functionality so we don't have to pass + # the large log file too many times + options.show_all = True + + with pytest.raises(SystemExit) as ex: + self.system.log_to_use = options.file + run(self.system, options) + assert ex.code == 0 + + out, _ = capsys.readouterr() + assert "Using Log File: \x1b[0m\x1b[1;32mtests/assets/logs/messages" in out + assert "OOM Incidents: \x1b[0m\x1b[1;31m19\x1b[0m" in out + assert "OOM Incident: \x1b[0m\x1b[0;96m19\x1b[0m" in out + assert "Displaying all OOM incidents:" in out diff --git a/tests/test_system.py b/tests/test_system.py index 40d9ef4..fc5a5bb 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -26,7 +26,7 @@ class TestSystem: "dmesg": False, "quick": False, "version": None, - "show_all": False + "show_all": False, } ) @@ -37,25 +37,6 @@ def test_distro_info_imports(self): assert distro_info[0] is not None assert distro_info[1] is not None - def test_file_processing(self, capsys): - # Test specific functionality when '-f messages' is passed - options = self.values - options.file = "tests/assets/logs/messages" - # While we're here, we might as well test the --all functionality so we don't have to pass - # the large log file too many times - options.show_all = True - - with pytest.raises(SystemExit) as ex: - self.system.log_to_use = options.file - run(self.system, options) - assert ex.code == 0 - - out, _ = capsys.readouterr() - assert "Using Log File: \x1b[0m\x1b[1;32mtests/assets/logs/messages" in out - assert "OOM Incidents: \x1b[0m\x1b[1;31m19\x1b[0m" in out - assert "OOM Incident: \x1b[0m\x1b[0;96m19\x1b[0m" in out - assert "Displaying all OOM incidents:" in out - def test_default_system_log(self): # Test default system log file options = self.values diff --git a/tests/test_validate_options.py b/tests/test_validate_options.py index cc37232..3396bcd 100644 --- a/tests/test_validate_options.py +++ b/tests/test_validate_options.py @@ -26,7 +26,7 @@ class TestSystem: "dmesg": False, "quick": False, "version": None, - "show_all": False + "show_all": False, } )