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

Invoke m.Run on TestMain and fix test flakiness #41891

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion filebeat/autodiscover/builder/hints/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package hints

import (
"os"
"path/filepath"
"testing"

Expand All @@ -30,8 +31,10 @@ import (
"github.com/elastic/elastic-agent-libs/paths"
)

func TestMain(t *testing.M) {
func TestMain(m *testing.M) {
InitializeModule()

os.Exit(m.Run())
}

func TestGenerateHints(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions filebeat/processor/add_kubernetes_metadata/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import (
"fmt"
"os"
"runtime"
"testing"

Expand All @@ -36,6 +37,8 @@

func TestMain(m *testing.M) {
InitializeModule()

os.Exit(m.Run())
}

func TestLogsPathMatcher_InvalidSource1(t *testing.T) {
Expand Down Expand Up @@ -181,11 +184,11 @@
func executeTestWithResourceType(t *testing.T, cfgLogsPath string, cfgResourceType string, source string, expectedResult string) {
testConfig := conf.NewConfig()
if cfgLogsPath != "" {
testConfig.SetString("logs_path", -1, cfgLogsPath)

Check failure on line 187 in filebeat/processor/add_kubernetes_metadata/matchers_test.go

View workflow job for this annotation

GitHub Actions / lint (windows)

Error return value of `testConfig.SetString` is not checked (errcheck)

Check failure on line 187 in filebeat/processor/add_kubernetes_metadata/matchers_test.go

View workflow job for this annotation

GitHub Actions / lint (linux)

Error return value of `testConfig.SetString` is not checked (errcheck)
}

if cfgResourceType != "" {
testConfig.SetString("resource_type", -1, cfgResourceType)

Check failure on line 191 in filebeat/processor/add_kubernetes_metadata/matchers_test.go

View workflow job for this annotation

GitHub Actions / lint (windows)

Error return value of `testConfig.SetString` is not checked (errcheck)

Check failure on line 191 in filebeat/processor/add_kubernetes_metadata/matchers_test.go

View workflow job for this annotation

GitHub Actions / lint (linux)

Error return value of `testConfig.SetString` is not checked (errcheck)
}

logMatcher, err := newLogsPathMatcher(*testConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package token

import (
"io/ioutil"

Check failure on line 21 in metricbeat/autodiscover/appender/kubernetes/token/token_test.go

View workflow job for this annotation

GitHub Actions / lint (windows)

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)

Check failure on line 21 in metricbeat/autodiscover/appender/kubernetes/token/token_test.go

View workflow job for this annotation

GitHub Actions / lint (linux)

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"os"
"testing"

Expand All @@ -31,6 +31,8 @@

func TestMain(m *testing.M) {
InitializeModule()

os.Exit(m.Run())
}

func TestTokenAppender(t *testing.T) {
Expand Down Expand Up @@ -97,7 +99,7 @@
assert.Equal(t, len(cfgs), 1)

out := mapstr.M{}
cfgs[0].Unpack(&out)

Check failure on line 102 in metricbeat/autodiscover/appender/kubernetes/token/token_test.go

View workflow job for this annotation

GitHub Actions / lint (windows)

Error return value of `(*github.com/elastic/elastic-agent-libs/config.C).Unpack` is not checked (errcheck)

Check failure on line 102 in metricbeat/autodiscover/appender/kubernetes/token/token_test.go

View workflow job for this annotation

GitHub Actions / lint (linux)

Error return value of `(*github.com/elastic/elastic-agent-libs/config.C).Unpack` is not checked (errcheck)

assert.Equal(t, out, test.result)
deleteFile("test")
Expand All @@ -105,7 +107,7 @@
}

func writeFile(name, message string) {
ioutil.WriteFile(name, []byte(message), os.ModePerm)

Check failure on line 110 in metricbeat/autodiscover/appender/kubernetes/token/token_test.go

View workflow job for this annotation

GitHub Actions / lint (windows)

Error return value of `ioutil.WriteFile` is not checked (errcheck)

Check failure on line 110 in metricbeat/autodiscover/appender/kubernetes/token/token_test.go

View workflow job for this annotation

GitHub Actions / lint (linux)

Error return value of `ioutil.WriteFile` is not checked (errcheck)
}

func deleteFile(name string) {
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/autodiscover/builder/hints/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (

func TestMain(m *testing.M) {
InitializeModule()

os.Exit(m.Run())
}

func TestGenerateHints(t *testing.T) {
Expand Down
Loading