Skip to content

Commit

Permalink
Test export commands in all Beats (#20016)
Browse files Browse the repository at this point in the history
This adds 4 new integration tests to all Beats that test export commands:

> beatname export ilm-policy
> beatname export template
> beatname export index-pattern
> beatname export config
  • Loading branch information
adriansr authored Jul 20, 2020
1 parent fe30916 commit 813763f
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 8 deletions.
3 changes: 2 additions & 1 deletion auditbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion filebeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
3 changes: 2 additions & 1 deletion heartbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
3 changes: 2 additions & 1 deletion journalbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
67 changes: 67 additions & 0 deletions libbeat/tests/system/beat/common_tests.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion libbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from base import BaseTest
from beat import common_tests

import json
import os
Expand All @@ -9,7 +10,7 @@
import unittest


class Test(BaseTest):
class Test(BaseTest, common_tests.TestExportsMixin):

def test_base(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion metricbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
11 changes: 11 additions & 0 deletions packetbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion winlogbeat/tests/system/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import sys
import unittest
from winlogbeat import BaseTest
from beat import common_tests

"""
Contains tests for config parsing.
"""


@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
class Test(BaseTest):
class Test(BaseTest, common_tests.TestExportsMixin):

def test_valid_config(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion x-pack/functionbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 813763f

Please sign in to comment.