forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test export commands in all Beats (elastic#20016)
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
1 parent
482f520
commit 41e7a8e
Showing
10 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters