Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare event by event in testdata framework to avoid sorting problems #13747

Merged
merged 3 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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