Skip to content

Commit 61af38d

Browse files
authored
Test export subcommands (#1482) (#1498)
* test export config and template subcommands * export always uses \n, even on windows
1 parent 85779da commit 61af38d

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

tests/system/apmserver.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ def setUp(self):
8888
shutil.copy(self._beat_path_join(pipeline_def), target_dir)
8989

9090
self.render_config_template(**self.config())
91-
self.apmserver_proc = self.start_beat()
91+
self.apmserver_proc = self.start_beat(**self.start_args())
92+
self.wait_until_started()
93+
94+
def start_args(self):
95+
return {}
96+
97+
def wait_until_started(self):
9298
self.wait_until(lambda: self.log_contains("Starting apm-server"))
9399

94100
def assert_no_logged_warnings(self, suppress=None):

tests/system/test_export.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import json
2+
import os
3+
import yaml
4+
5+
from apmserver import ServerSetUpBaseTest
6+
7+
8+
class SubCommandTest(ServerSetUpBaseTest):
9+
def wait_until_started(self):
10+
self.apmserver_proc.check_wait()
11+
12+
# command and go test output is combined in log, pull out the command output
13+
log = self.get_log()
14+
pos = -1
15+
for _ in range(2):
16+
# export always uses \n, not os.linesep
17+
pos = log[:pos].rfind("\n")
18+
self.command_output = log[:pos]
19+
for trimmed in log[pos:].strip().splitlines():
20+
# ensure only skipping expected lines
21+
assert trimmed.split(None, 1)[0] in ("PASS", "coverage:"), trimmed
22+
23+
24+
class ExportConfigTest(SubCommandTest):
25+
"""
26+
Test export config subcommand.
27+
"""
28+
29+
def start_args(self):
30+
return {
31+
"extra_args": ["export", "config"],
32+
"logging_args": None,
33+
}
34+
35+
def test_export_config(self):
36+
"""
37+
Test export config works
38+
"""
39+
config = yaml.load(self.command_output)
40+
total_fields_limit = config['setup']['template']['settings']['index']['mapping']['total_fields']['limit']
41+
assert total_fields_limit == 2000, total_fields_limit
42+
43+
44+
class ExportTemplateTest(SubCommandTest):
45+
"""
46+
Test export template subcommand.
47+
"""
48+
49+
def start_args(self):
50+
return {
51+
"extra_args": ["export", "template"],
52+
"logging_args": None,
53+
}
54+
55+
def test_export_template(self):
56+
"""
57+
Test export template works
58+
"""
59+
template = json.loads(self.command_output)
60+
total_fields_limit = template['settings']['index']['mapping']['total_fields']['limit']
61+
assert total_fields_limit == 2000, total_fields_limit

0 commit comments

Comments
 (0)