diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2022-12-02 16:20:01 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2023-01-12 12:21:25 -0500 |
commit | 131b3bcf5691a158598bed30bd0af6ac9c96737c (patch) | |
tree | e70b824a077300eea34513a6305568c38696ac79 /tests/report_tests/options_tests/options_tests.py | |
parent | ca8a8a7b9f452a81c5654234918b99092620bf13 (diff) | |
download | sos-131b3bcf5691a158598bed30bd0af6ac9c96737c.tar.gz |
[testing] Change location of mocked files for tests
Previously, mocked files were kept under the `tests/test_data/`
directory and generally mimic'd the file location they would be
temporarily copied to during the execution of their relevant tests.
This has a few maintainability drawbacks, and the handling of the
`files` attribute for test cases as either strings or tuples is at best
confusing.
Improve on this by instead making the `files` references relative to
where the test case file is written. This enables easier maintenance by
keeping all test requirements closer together, rather than spread across
the repo. As such, the `files` attribute now requires a list of tuples,
taking the form `(relative_src, absolute_dest)`. Additionally, fake
plugins for tests that need them to artificially test a specific
criteria should also be included in the test's subdir now.
Along with this change, move several StageTwo tests to their own subdirs
that now contain both the test cases and the needed files for mocking.
This should be the new design pattern going forward - if a test needs to
mock files of any kind, put it in a new subdirectory (and if it doesn't
need to mock files, continue to keep it in the relevant directory within
the test suite).
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests/report_tests/options_tests/options_tests.py')
-rw-r--r-- | tests/report_tests/options_tests/options_tests.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/report_tests/options_tests/options_tests.py b/tests/report_tests/options_tests/options_tests.py new file mode 100644 index 00000000..f8e1ee60 --- /dev/null +++ b/tests/report_tests/options_tests/options_tests.py @@ -0,0 +1,45 @@ +# This file is part of the sos project: https://github.com/sosreport/sos +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# version 2 of the GNU General Public License. +# +# See the LICENSE file in the source distribution for further information. + + +from sos_tests import StageTwoReportTest + + +class OptionsFromConfigTest(StageTwoReportTest): + """Ensure that we handle options specified in sos.conf properly + + :avocado: tags=stagetwo + """ + + files = [('options_tests_sos.conf', '/etc/sos/sos.conf')] + sos_cmd = '-v ' + + def test_case_id_from_config(self): + self.assertTrue('8675309' in self.archive) + + def test_plugins_skipped_from_config(self): + self.assertPluginNotIncluded(['networking', 'logs']) + + def test_plugopts_logged_from_config(self): + self.assertSosLogContains( + "Set kernel plugin option to \(name=with-timer, desc='gather /proc/timer\* statistics', value=True, default=False\)" + ) + self.assertSosLogContains( + "Set kernel plugin option to \(name=trace, desc='gather /sys/kernel/debug/tracing/trace file', value=True, default=False\)" + ) + + def test_disabled_plugopts_not_loaded(self): + self.assertSosLogNotContains("Set networking plugin option to") + + def test_plugopts_actually_set(self): + self.assertFileCollected('sys/kernel/debug/tracing/trace') + + def test_effective_options_logged_correctly(self): + self.assertSosLogContains( + "effective options now: --batch --case-id 8675309 --plugopts kernel.with-timer=on,kernel.trace=yes --skip-plugins networking,logs" + ) |