Skip to content

Commit

Permalink
Compare event by event in testdata framework to avoid sorting probl…
Browse files Browse the repository at this point in the history
…ems (#13747)
  • Loading branch information
ChrsMark committed Sep 23, 2019
1 parent b032ee1 commit 3e0cf6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
- Add checks for types and formats used in fields definitions in `fields.yml` files. {pull}13188[13188]
- Makefile included in generator copies files from beats repository using `git archive` instead of cp. {pull}13193[13193]
- Strip debug symbols from binaries to reduce binary sizes. {issue}12768[12768]
- Compare event by event in `testadata` framework to avoid sorting problems {pull}13747[13747]
1 change: 0 additions & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Added `monitoring.cluster_uuid` setting to associate Beat data with specified ES cluster in Stack Monitoring UI. {pull}13182[13182]
- Add autodetection mode for add_kubernetes_metadata and enable it by default in included configuration files. {pull}13473[13473]


*Auditbeat*

- Auditd module: Add `event.outcome` and `event.type` for ECS. {pull}11432[11432]
Expand Down
29 changes: 20 additions & 9 deletions metricbeat/mb/testing/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/pkg/errors"

"github.com/mitchellh/hashstructure"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"

"github.com/elastic/beats/libbeat/asset"
Expand Down Expand Up @@ -263,18 +262,30 @@ func runTest(t *testing.T, file string, module, metricSetName string, config Dat
}
}

output, err := json.Marshal(&data)
if err != nil {
t.Fatal(err)
for _, event := range data {
// ensure the event is in expected list
found := -1
for i, expectedEvent := range expectedMap {
if event.String() == expectedEvent.String() {
found = i
break
}
}
if found > -1 {
expectedMap = append(expectedMap[:found], expectedMap[found+1:]...)
} else {
t.Errorf("Event was not expected: %+v", event)
}
}

expectedJSON, err := json.Marshal(&expectedMap)
if err != nil {
t.Fatal(err)
if len(expectedMap) > 0 {
t.Error("Some events were missing:")
for _, e := range expectedMap {
t.Error(e)
}
t.Fatal()
}

assert.Equal(t, string(expectedJSON), string(output))

if strings.HasSuffix(file, "docs."+config.Suffix) {
writeDataJSON(t, data[0], filepath.Join(config.WritePath, "data.json"))
}
Expand Down

0 comments on commit 3e0cf6c

Please sign in to comment.