Skip to content

Commit

Permalink
golangci-lint: remove error checks from all instances of logp.Develop…
Browse files Browse the repository at this point in the history
…mentSetup()
  • Loading branch information
mmat11 committed Nov 10, 2023
1 parent d06f068 commit 156a14d
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 35 deletions.
4 changes: 1 addition & 3 deletions filebeat/input/filestream/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ type registryEntry struct {
}

func newInputTestingEnvironment(t *testing.T) *inputTestingEnvironment {
if err := logp.DevelopmentSetup(logp.ToObserverOutput()); err != nil {
t.Fatalf("error setting up dev logging: %s", err)
}
logp.DevelopmentSetup(logp.ToObserverOutput())

t.Cleanup(func() {
if t.Failed() {
Expand Down
8 changes: 3 additions & 5 deletions filebeat/input/filestream/fswatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,14 @@ scanner:
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()

err := logp.DevelopmentSetup(logp.ToObserverOutput())
require.NoError(t, err)
logp.DevelopmentSetup(logp.ToObserverOutput())

fw := createWatcherWithConfig(t, paths, cfgStr)
go fw.Run(ctx)

basename := "created.log"
filename := filepath.Join(dir, basename)
err = os.WriteFile(filename, nil, 0777)
err := os.WriteFile(filename, nil, 0777)
require.NoError(t, err)

t.Run("issues a warning in logs", func(t *testing.T) {
Expand Down Expand Up @@ -373,8 +372,7 @@ scanner:
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

err = logp.DevelopmentSetup(logp.ToObserverOutput())
require.NoError(t, err)
logp.DevelopmentSetup(logp.ToObserverOutput())

fw := createWatcherWithConfig(t, paths, cfgStr)

Expand Down
4 changes: 1 addition & 3 deletions libbeat/autodiscover/autodiscover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,7 @@ func printDebugLogsOnFailure(t *testing.T) {
// Use the following line to have the logs being printed
// in real time.
// logp.DevelopmentSetup(logp.WithLevel(logp.DebugLevel), logp.WithSelectors("*"))
if err := logp.DevelopmentSetup(logp.ToObserverOutput()); err != nil {
t.Fatalf("error setting up dev logging: %s", err)
}
logp.DevelopmentSetup(logp.ToObserverOutput())

t.Cleanup(func() {
if t.Failed() {
Expand Down
7 changes: 2 additions & 5 deletions libbeat/cmd/instance/locks/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ import (
)

func TestMain(m *testing.M) {
err := logp.DevelopmentSetup()
if err != nil {
fmt.Fprintf(os.Stderr, "error creating logger: %s\n", err)
os.Exit(1)
}
logp.DevelopmentSetup()

tmp, err := os.MkdirTemp("", "pidfile_test")
defer os.RemoveAll(tmp)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions libbeat/publisher/queue/queuetest/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"sync"
"testing"

"gotest.tools/assert"

"github.com/elastic/elastic-agent-libs/logp"
)

Expand Down Expand Up @@ -88,8 +86,7 @@ func withOptLogOutput(capture bool, fn func(*testing.T)) func(*testing.T) {
if debug {
level = logp.DebugLevel
}
err = logp.DevelopmentSetup(logp.WithLevel(level))
assert.NilError(t, err)
logp.DevelopmentSetup(logp.WithLevel(level))
fn(t)
}
}
Expand Down
3 changes: 1 addition & 2 deletions metricbeat/module/system/filesystem/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import (
func TestFetch(t *testing.T) {
f := mbtest.NewReportingMetricSetV2Error(t, getConfig())
events, errs := mbtest.ReportingFetchV2Error(f)
err := logp.DevelopmentSetup()
assert.NoError(t, err)
logp.DevelopmentSetup()
assert.Empty(t, errs)
if !assert.NotEmpty(t, events) {
t.FailNow()
Expand Down
4 changes: 1 addition & 3 deletions metricbeat/module/system/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
_ "github.com/elastic/beats/v7/metricbeat/module/system"
Expand All @@ -33,8 +32,7 @@ import (
)

func TestFetch(t *testing.T) {
err := logp.DevelopmentSetup()
require.NoError(t, err, "could not set the logger to DevelopmentSetup")
logp.DevelopmentSetup()

f := mbtest.NewReportingMetricSetV2Error(t, getConfig())
events, errs := mbtest.ReportingFetchV2Error(f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func TestData(t *testing.T) {
}

func TestFetch(t *testing.T) {
err := logp.DevelopmentSetup()
require.NoError(t, err)
logp.DevelopmentSetup()
f := mbtest.NewReportingMetricSetV2Error(t, getConfig())
events, errs := mbtest.ReportingFetchV2Error(f)

Expand All @@ -53,14 +52,13 @@ func TestFetch(t *testing.T) {
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(),
event.StringToPrint())

_, err = event.GetValue("system.process.summary")
_, err := event.GetValue("system.process.summary")
require.NoError(t, err)

}

func TestStateNames(t *testing.T) {
err := logp.DevelopmentSetup()
require.NoError(t, err)
logp.DevelopmentSetup()
f := mbtest.NewReportingMetricSetV2Error(t, getConfig())
events, errs := mbtest.ReportingFetchV2Error(f)

Expand Down
2 changes: 1 addition & 1 deletion packetbeat/protos/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func newDNS(store *eventStore, verbose bool) *dnsPlugin {
if verbose {
level = logp.DebugLevel
}
_ = logp.DevelopmentSetup(
logp.DevelopmentSetup(
logp.WithLevel(level),
logp.WithSelectors("dns"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ func TestGetTimeIntervalAligner(t *testing.T) {
}

func TestGetFilterForMetric(t *testing.T) {
if err := logp.DevelopmentSetup(logp.ToObserverOutput()); err != nil {
t.Fatalf("cannot initialise logger on development mode: %+v", err)
}

logp.DevelopmentSetup(logp.ToObserverOutput())
var logger = logp.NewLogger("TestGetFilterForMetric")

cases := []struct {
Expand Down

0 comments on commit 156a14d

Please sign in to comment.