forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to verify template content
We recently started to move fields.yml into the Golang binary to be used internally. To make sure the loading important and loading of all the data into the binary works as expected for Metricbeat, this adds some basic tests. Related to elastic#7605.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import metricbeat | ||
import json | ||
from nose.plugins.skip import SkipTest | ||
|
||
|
||
class Test(metricbeat.BaseTest): | ||
|
||
def test_export_template(self): | ||
""" | ||
Test export template works and contains all fields | ||
""" | ||
|
||
if os.name == "nt": | ||
raise SkipTest | ||
|
||
self.render_config_template("metricbeat", | ||
os.path.join(self.working_dir, | ||
"metricbeat.yml"), | ||
) | ||
|
||
# Remove fields.yml to make sure template is built from internal binary data | ||
os.remove(os.path.join(self.working_dir, "fields.yml")) | ||
|
||
exit_code = self.run_beat( | ||
logging_args=[], | ||
extra_args=["export", "template"], | ||
config="metricbeat.yml", | ||
output="template.json" | ||
) | ||
assert exit_code == 0 | ||
|
||
template_path = os.path.join(self.working_dir, "template.json") | ||
template_content = "" | ||
|
||
# Read in all json lines and discard the coverage info | ||
with open(template_path) as f: | ||
for line in f: | ||
template_content += line | ||
if line.startswith("}"): | ||
break | ||
|
||
t = json.loads(template_content) | ||
|
||
properties = t["mappings"]["doc"]["properties"] | ||
|
||
# Check libbeat fields | ||
assert properties["@timestamp"] == {"type": "date"} | ||
assert properties["host"]["properties"]["name"] == {"type": "keyword", "ignore_above": 1024} | ||
|
||
# Check metricbeat generic field | ||
assert properties["metricset"]["properties"]["host"] == {"type": "keyword", "ignore_above": 1024} | ||
|
||
# Check module specific field | ||
assert properties["system"]["properties"]["cpu"]["properties"]["cores"] == {"type": "long"} |