diff --git a/auditbeat/tests/system/test_base.py b/auditbeat/tests/system/test_base.py index 8a15d004df9..8dfa64f8ac3 100644 --- a/auditbeat/tests/system/test_base.py +++ b/auditbeat/tests/system/test_base.py @@ -6,9 +6,10 @@ from auditbeat import * from elasticsearch import Elasticsearch from beat.beat import INTEGRATION_TESTS +from beat import common_tests -class Test(BaseTest): +class Test(BaseTest, common_tests.TestExportsMixin): def test_start_stop(self): """ Auditbeat starts and stops without error. diff --git a/filebeat/tests/system/test_base.py b/filebeat/tests/system/test_base.py index 80394e0a34e..2b73a0165a7 100644 --- a/filebeat/tests/system/test_base.py +++ b/filebeat/tests/system/test_base.py @@ -3,9 +3,10 @@ from filebeat import BaseTest from elasticsearch import Elasticsearch from beat.beat import INTEGRATION_TESTS +from beat import common_tests -class Test(BaseTest): +class Test(BaseTest, common_tests.TestExportsMixin): def test_base(self): """ diff --git a/heartbeat/tests/system/test_base.py b/heartbeat/tests/system/test_base.py index 683ffde212a..47bf97f2561 100644 --- a/heartbeat/tests/system/test_base.py +++ b/heartbeat/tests/system/test_base.py @@ -4,10 +4,11 @@ from heartbeat import BaseTest from elasticsearch import Elasticsearch from beat.beat import INTEGRATION_TESTS +from beat import common_tests import nose.tools -class Test(BaseTest): +class Test(BaseTest, common_tests.TestExportsMixin): def test_base(self): """ diff --git a/journalbeat/tests/system/test_base.py b/journalbeat/tests/system/test_base.py index a94d4a7473c..c3898dfdbc9 100644 --- a/journalbeat/tests/system/test_base.py +++ b/journalbeat/tests/system/test_base.py @@ -6,9 +6,10 @@ import time import yaml from shutil import copyfile +from beat import common_tests -class Test(BaseTest): +class Test(BaseTest, common_tests.TestExportsMixin): @unittest.skipUnless(sys.platform.startswith("linux"), "Journald only on Linux") def test_start_with_local_journal(self): diff --git a/libbeat/tests/system/beat/common_tests.py b/libbeat/tests/system/beat/common_tests.py new file mode 100644 index 00000000000..ed390c44df5 --- /dev/null +++ b/libbeat/tests/system/beat/common_tests.py @@ -0,0 +1,67 @@ +import json +import unittest +import yaml + +from beat.beat import INTEGRATION_TESTS + + +class TestExportsMixin: + + def run_export_cmd(self, cmd, extra=[]): + """ + Runs the given export command and returns the output as a string. + Raises an exception if the command fails. + :param cmd: the export command + :param extra: Extra arguments (optional) + :return: The output as a string. + """ + self.render_config_template() + + args = ["export", cmd] + if len(extra) != 0: + args += extra + exit_code = self.run_beat(extra_args=args, logging_args=[]) + assert exit_code == 0 + output = self.get_log() + trailer = "\nPASS\n" + pos = output.rfind(trailer) + if pos == -1: + raise Exception("didn't return expected trailer:{} got:{}".format( + trailer.__repr__(), output[-100:].__repr__())) + return output[:pos] + + @unittest.skipUnless(INTEGRATION_TESTS, "integration test") + def test_export_ilm_policy(self): + """ + Test that the ilm-policy can be exported with `export ilm-policy` + """ + output = self.run_export_cmd("ilm-policy") + js = json.loads(output) + assert "policy" in js + + @unittest.skipUnless(INTEGRATION_TESTS, "integration test") + def test_export_template(self): + """ + Test that the template can be exported with `export template` + """ + output = self.run_export_cmd("template") + js = json.loads(output) + assert "index_patterns" in js and "mappings" in js + + @unittest.skipUnless(INTEGRATION_TESTS, "integration test") + def test_export_index_pattern(self): + """ + Test that the index-pattern can be exported with `export index-pattern` + """ + output = self.run_export_cmd("index-pattern") + js = json.loads(output) + assert "objects" in js + + @unittest.skipUnless(INTEGRATION_TESTS, "integration test") + def test_export_config(self): + """ + Test that the config can be exported with `export config` + """ + output = self.run_export_cmd("config") + yml = yaml.load(output) + assert isinstance(yml, dict) diff --git a/libbeat/tests/system/test_base.py b/libbeat/tests/system/test_base.py index 10fe859bf1e..330b831041a 100644 --- a/libbeat/tests/system/test_base.py +++ b/libbeat/tests/system/test_base.py @@ -1,4 +1,5 @@ from base import BaseTest +from beat import common_tests import json import os @@ -9,7 +10,7 @@ import unittest -class Test(BaseTest): +class Test(BaseTest, common_tests.TestExportsMixin): def test_base(self): """ diff --git a/metricbeat/tests/system/test_base.py b/metricbeat/tests/system/test_base.py index 4f680d29172..7df5152ccd6 100644 --- a/metricbeat/tests/system/test_base.py +++ b/metricbeat/tests/system/test_base.py @@ -6,9 +6,10 @@ from metricbeat import BaseTest from elasticsearch import Elasticsearch from beat.beat import INTEGRATION_TESTS +from beat import common_tests -class Test(BaseTest): +class Test(BaseTest, common_tests.TestExportsMixin): COMPOSE_SERVICES = ['elasticsearch', 'kibana'] diff --git a/packetbeat/tests/system/test_base.py b/packetbeat/tests/system/test_base.py new file mode 100644 index 00000000000..959d36b3911 --- /dev/null +++ b/packetbeat/tests/system/test_base.py @@ -0,0 +1,11 @@ +import os +import sys +from packetbeat import BaseTest + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../libbeat/tests/system'))) + +from beat import common_tests + + +class Test(BaseTest, common_tests.TestExportsMixin): + pass diff --git a/winlogbeat/tests/system/test_config.py b/winlogbeat/tests/system/test_config.py index 16862bf44f9..18df0594fca 100644 --- a/winlogbeat/tests/system/test_config.py +++ b/winlogbeat/tests/system/test_config.py @@ -3,6 +3,7 @@ import sys import unittest from winlogbeat import BaseTest +from beat import common_tests """ Contains tests for config parsing. @@ -10,7 +11,7 @@ @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") -class Test(BaseTest): +class Test(BaseTest, common_tests.TestExportsMixin): def test_valid_config(self): """ diff --git a/x-pack/functionbeat/tests/system/test_base.py b/x-pack/functionbeat/tests/system/test_base.py index b351ed63340..895d23d4c3e 100644 --- a/x-pack/functionbeat/tests/system/test_base.py +++ b/x-pack/functionbeat/tests/system/test_base.py @@ -3,9 +3,10 @@ import json import os import unittest +from beat import common_tests -class Test(BaseTest): +class Test(BaseTest, common_tests.TestExportsMixin): @unittest.skip("temporarily disabled") def test_base(self): """