From 3e0cf6c63c9b83e4efe55f5e08e8daaa53f1cfe6 Mon Sep 17 00:00:00 2001 From: Chris Mark Date: Mon, 23 Sep 2019 11:03:19 +0300 Subject: [PATCH] Compare event by event in `testdata` framework to avoid sorting problems (#13747) --- CHANGELOG-developer.next.asciidoc | 1 + CHANGELOG.next.asciidoc | 1 - metricbeat/mb/testing/testdata.go | 29 ++++++++++++++++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index 12d76adabc1..2aeaf33358a 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -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] diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index fcced9f93ad..74a595ac4fb 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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] diff --git a/metricbeat/mb/testing/testdata.go b/metricbeat/mb/testing/testdata.go index 48dee790937..2f9f8cc0036 100644 --- a/metricbeat/mb/testing/testdata.go +++ b/metricbeat/mb/testing/testdata.go @@ -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" @@ -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")) }