Skip to content

Commit

Permalink
Improve template testing (elastic#3425)
Browse files Browse the repository at this point in the history
Template tests broke in the past several times because we have a test template which is not updated automatically. The tests are now changed so that the libbeat template is generated and tested. This guarantees that the templates we actually use are tested. This requires for integration tests also for libbeat to be called `make update`.

* Switch to `update` also for libbeat.
* Files generated by `update` are added go `.gitignore` as these files should not be versioned.
* Add heartbeat to template tests
* Remove static test templates as not needed anymore.
  • Loading branch information
ruflin authored and tsg committed Jan 20, 2017
1 parent ae445a7 commit f957f70
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 88 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ coverage-report:

.PHONY: update
update:
$(MAKE) -C libbeat collect
$(foreach var,$(BEATS),$(MAKE) -C $(var) update || exit 1;)
$(foreach var,$(PROJECTS),$(MAKE) -C $(var) update || exit 1;)

.PHONY: clean
clean:
Expand Down Expand Up @@ -117,7 +116,7 @@ upload-release:
aws s3 cp --recursive --acl public-read build/upload s3://download.elasticsearch.org/beats/

.PHONY: notice
notice:
notice:
python dev-tools/generate_notice.py .


5 changes: 5 additions & 0 deletions libbeat/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ _testmain.go
.idea
.jenkins

/libbeat.template-es2x.json
/libbeat.yml
/libbeat.full.yml
/libbeat.template.json
/docs/fields.asciidoc
12 changes: 7 additions & 5 deletions libbeat/outputs/elasticsearch/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func TestLoadTemplate(t *testing.T) {
assert.Nil(t, err)

// Load template
absPath, err := filepath.Abs("../../tests/files/")
absPath, err := filepath.Abs("../../")
assert.NotNil(t, absPath)
assert.Nil(t, err)

templatePath := absPath + "/template.json"
templatePath := absPath + "/libbeat.template.json"
if strings.HasPrefix(client.Connection.version, "2.") {
templatePath = absPath + "/template-es2x.json"
templatePath = absPath + "/libbeat.template-es2x.json"
}
content, err := readTemplate(templatePath)
assert.Nil(t, err)
Expand Down Expand Up @@ -96,6 +96,8 @@ func TestLoadBeatsTemplate(t *testing.T) {

beats := []string{
"filebeat",
"heartbeat",
"libbeat",
"packetbeat",
"metricbeat",
"winlogbeat",
Expand Down Expand Up @@ -155,10 +157,10 @@ func TestOutputLoadTemplate(t *testing.T) {
// Make sure template is not yet there
assert.False(t, client.CheckTemplate("libbeat"))

templatePath := "../../../packetbeat/packetbeat.template.json"
templatePath := "../../libbeat.template.json"

if strings.HasPrefix(client.Connection.version, "2.") {
templatePath = "../../../packetbeat/packetbeat.template-es2x.json"
templatePath = "../../libbeat.template-es2x.json"
}

tPath, err := filepath.Abs(templatePath)
Expand Down
2 changes: 1 addition & 1 deletion libbeat/scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ test: unit

.PHONY: testsuite
testsuite: ## @testing Runs all tests and generates the coverage reports
testsuite: clean collect
testsuite: clean update
$(MAKE) unit-tests

# Setups environment if TEST_ENVIRONMENT is set to true
Expand Down
43 changes: 0 additions & 43 deletions libbeat/tests/files/template-es2x.json

This file was deleted.

36 changes: 0 additions & 36 deletions libbeat/tests/files/template.json

This file was deleted.

0 comments on commit f957f70

Please sign in to comment.