diff --git a/pkg/stanza/.golangci.yml b/pkg/stanza/.golangci.yml index 3022ffd93fc5..95ebbc6b04c1 100644 --- a/pkg/stanza/.golangci.yml +++ b/pkg/stanza/.golangci.yml @@ -131,6 +131,5 @@ issues: linters: - revive - gosec - - errcheck - misspell - govet diff --git a/pkg/stanza/operator/helper/parser_test.go b/pkg/stanza/operator/helper/parser_test.go index 8c8411cdf5be..8f4fba5da537 100644 --- a/pkg/stanza/operator/helper/parser_test.go +++ b/pkg/stanza/operator/helper/parser_test.go @@ -706,6 +706,6 @@ func writerWithFakeOut(t *testing.T) (*WriterOperator, *testutil.FakeOutput) { }, OutputIDs: []string{fakeOut.ID()}, } - writer.SetOutputs([]operator.Operator{fakeOut}) + require.NoError(t, writer.SetOutputs([]operator.Operator{fakeOut})) return writer, fakeOut } diff --git a/pkg/stanza/operator/input/file/benchmark_test.go b/pkg/stanza/operator/input/file/benchmark_test.go index a55bcd3d7a06..42822a4c13d7 100644 --- a/pkg/stanza/operator/input/file/benchmark_test.go +++ b/pkg/stanza/operator/input/file/benchmark_test.go @@ -37,11 +37,14 @@ type benchFile struct { log func(int) } -func simpleTextFile(file *os.File) *benchFile { +func simpleTextFile(b *testing.B, file *os.File) *benchFile { line := stringWithLength(49) + "\n" return &benchFile{ File: file, - log: func(_ int) { file.WriteString(line) }, + log: func(_ int) { + _, err := file.WriteString(line) + require.NoError(b, err) + }, } } @@ -146,7 +149,7 @@ func BenchmarkFileInput(b *testing.B) { files := []*benchFile{} for _, path := range bench.paths { file := openFile(b, filepath.Join(rootDir, path)) - files = append(files, simpleTextFile(file)) + files = append(files, simpleTextFile(b, file)) } cfg := bench.config() @@ -173,7 +176,9 @@ func BenchmarkFileInput(b *testing.B) { b.ResetTimer() err = op.Start(testutil.NewMockPersister("test")) - defer op.Stop() + defer func() { + require.NoError(b, op.Stop()) + }() require.NoError(b, err) // write the remainder of lines while running diff --git a/pkg/stanza/operator/input/file/file_test.go b/pkg/stanza/operator/input/file/file_test.go index b66bb5534fe3..bef54f3d08f4 100644 --- a/pkg/stanza/operator/input/file/file_test.go +++ b/pkg/stanza/operator/input/file/file_test.go @@ -42,7 +42,9 @@ See this issue for details: https://github.com/census-instrumentation/opencensus _ = openTemp(t, tempDir) err := operator.Start(testutil.NewMockPersister("test")) require.NoError(t, err) - operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() } // AddFields tests that the `log.file.name` and `log.file.path` fields are included @@ -59,7 +61,9 @@ func TestAddFileFields(t *testing.T) { writeString(t, temp, "testlog\n") require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() e := waitForOne(t, logReceived) require.Equal(t, filepath.Base(temp.Name()), e.Attributes["log.file.name"]) @@ -99,7 +103,9 @@ func TestAddFileResolvedFields(t *testing.T) { require.NoError(t, err) require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() e := waitForOne(t, logReceived) require.Equal(t, filepath.Base(symLinkPath), e.Attributes["log.file.name"]) @@ -160,7 +166,9 @@ func TestAddFileResolvedFieldsWithChangeOfSymlinkTarget(t *testing.T) { writeString(t, file1, "testlog\n") require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() e := waitForOne(t, logReceived) require.Equal(t, filepath.Base(symLinkPath), e.Attributes["log.file.name"]) @@ -199,7 +207,9 @@ func TestReadExistingLogs(t *testing.T) { writeString(t, temp, "testlog1\ntestlog2\n") require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, "testlog1") waitForMessage(t, logReceived, "testlog2") @@ -262,7 +272,9 @@ func TestReadUsingNopEncoding(t *testing.T) { require.Greater(t, bytesWritten, 0) require.NoError(t, err) require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() tc.test(t, logReceived) }) @@ -340,7 +352,9 @@ func TestNopEncodingDifferentLogSizes(t *testing.T) { require.Greater(t, bytesWritten, 0) require.NoError(t, err) require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() tc.test(t, logReceived) }) @@ -356,7 +370,9 @@ func TestReadNewLogs(t *testing.T) { // Poll once so we know this isn't a new file operator.poll(context.Background()) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() // Create a new file temp := openTemp(t, tempDir) @@ -376,7 +392,9 @@ func TestReadExistingAndNewLogs(t *testing.T) { t.Parallel() operator, logReceived, tempDir := newTestFileOperator(t, nil, nil) operator.persister = testutil.NewMockPersister("test") - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() // Start with a file with an entry in it, and expect that entry // to come through when we poll for the first time @@ -400,7 +418,9 @@ func TestStartAtEnd(t *testing.T) { cfg.StartAt = "end" }, nil) operator.persister = testutil.NewMockPersister("test") - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temp := openTemp(t, tempDir) writeString(t, temp, "testlog1\n") @@ -423,7 +443,9 @@ func TestStartAtEndNewFile(t *testing.T) { operator, logReceived, tempDir := newTestFileOperator(t, nil, nil) operator.persister = testutil.NewMockPersister("test") operator.startAtBeginning = false - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() operator.poll(context.Background()) temp := openTemp(t, tempDir) @@ -447,7 +469,9 @@ func TestNoNewline(t *testing.T) { writeString(t, temp, "testlog1\ntestlog2") require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, "testlog1") waitForMessage(t, logReceived, "testlog2") @@ -462,7 +486,9 @@ func TestSkipEmpty(t *testing.T) { writeString(t, temp, "testlog1\n\ntestlog2\n") require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, "testlog1") waitForMessage(t, logReceived, "testlog2") @@ -474,7 +500,9 @@ func TestSplitWrite(t *testing.T) { t.Parallel() operator, logReceived, tempDir := newTestFileOperator(t, nil, nil) operator.persister = testutil.NewMockPersister("test") - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temp := openTemp(t, tempDir) writeString(t, temp, "testlog1") @@ -491,7 +519,9 @@ func TestIgnoreEmptyFiles(t *testing.T) { t.Parallel() operator, logReceived, tempDir := newTestFileOperator(t, nil, nil) operator.persister = testutil.NewMockPersister("test") - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temp := openTemp(t, tempDir) temp2 := openTemp(t, tempDir) @@ -516,7 +546,9 @@ func TestDecodeBufferIsResized(t *testing.T) { operator, logReceived, tempDir := newTestFileOperator(t, nil, nil) require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temp := openTemp(t, tempDir) expected := stringWithLength(1<<12 + 1) @@ -536,7 +568,9 @@ func TestMultiFileSimple(t *testing.T) { writeString(t, temp2, "testlog2\n") require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessages(t, logReceived, []string{"testlog1", "testlog2"}) } @@ -571,7 +605,9 @@ func TestMultiFileParallel_PreloadedFiles(t *testing.T) { } require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessages(t, logReceived, expected) wg.Wait() @@ -595,7 +631,9 @@ func TestMultiFileParallel_LiveFiles(t *testing.T) { } require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temps := make([]*os.File, 0, numFiles) for i := 0; i < numFiles; i++ { @@ -629,7 +667,9 @@ func TestOffsetsAfterRestart(t *testing.T) { // Start the operator and expect a message require.NoError(t, operator.Start(persister)) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, "testlog1") // Restart the operator. Stop and build a new @@ -655,7 +695,9 @@ func TestOffsetsAfterRestart_BigFiles(t *testing.T) { // Start the operator require.NoError(t, operator.Start(persister)) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, log1) // Restart the operator @@ -679,7 +721,9 @@ func TestOffsetsAfterRestart_BigFilesWrittenWhileOff(t *testing.T) { // Start the operator and expect the first message require.NoError(t, operator.Start(persister)) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, log1) // Stop the operator and write a new message @@ -703,12 +747,15 @@ func TestManyLogsDelivered(t *testing.T) { // Start the operator require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() // Write lots of logs temp := openTemp(t, tempDir) for _, message := range expectedMessages { - temp.WriteString(message + "\n") + _, err := temp.WriteString(message + "\n") + require.NoError(t, err) } // Expect each of them to come through once @@ -741,7 +788,9 @@ func TestFileBatching(t *testing.T) { }, ) operator.persister = testutil.NewMockPersister("test") - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temps := make([]*os.File, 0, files) for i := 0; i < files; i++ { @@ -752,7 +801,8 @@ func TestFileBatching(t *testing.T) { for i, temp := range temps { for j := 0; j < linesPerFile; j++ { message := fmt.Sprintf("%s %d %d", stringWithLength(100), i, j) - temp.WriteString(message + "\n") + _, err := temp.WriteString(message + "\n") + require.NoError(t, err) expectedMessages = append(expectedMessages, message) } } @@ -769,7 +819,8 @@ func TestFileBatching(t *testing.T) { for i, temp := range temps { for j := 0; j < linesPerFile; j++ { message := fmt.Sprintf("%s %d %d", stringWithLength(20), i, j) - temp.WriteString(message + "\n") + _, err := temp.WriteString(message + "\n") + require.NoError(t, err) expectedMessages = append(expectedMessages, message) } } @@ -787,7 +838,9 @@ func TestFileReader_FingerprintUpdated(t *testing.T) { t.Parallel() operator, logReceived, tempDir := newTestFileOperator(t, nil, nil) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temp := openTemp(t, tempDir) tempCopy := openFile(t, temp.Name()) @@ -830,7 +883,9 @@ func TestFingerprintGrowsAndStops(t *testing.T) { operator, _, tempDir := newTestFileOperator(t, func(cfg *InputConfig) { cfg.FingerprintSize = helper.ByteSize(maxFP) }, nil) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temp := openTemp(t, tempDir) tempCopy := openFile(t, temp.Name()) @@ -940,7 +995,9 @@ func TestEncodings(t *testing.T) { require.NoError(t, err) require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() for _, expected := range tc.expected { select { diff --git a/pkg/stanza/operator/input/file/finder_test.go b/pkg/stanza/operator/input/file/finder_test.go index 3890dec0efeb..4d8347a7718e 100644 --- a/pkg/stanza/operator/input/file/finder_test.go +++ b/pkg/stanza/operator/input/file/finder_test.go @@ -136,8 +136,8 @@ func TestFinder(t *testing.T) { expected := absPath(tempDir, tc.expected) for _, f := range files { - os.MkdirAll(filepath.Dir(f), 0755) - ioutil.WriteFile(f, []byte(filepath.Base(f)), 0755) + require.NoError(t, os.MkdirAll(filepath.Dir(f), 0755)) + require.NoError(t, ioutil.WriteFile(f, []byte(filepath.Base(f)), 0755)) } finder := Finder{include, exclude} diff --git a/pkg/stanza/operator/input/file/fingerprint_test.go b/pkg/stanza/operator/input/file/fingerprint_test.go index 5d1ca5fd197b..dbcdda2725ee 100644 --- a/pkg/stanza/operator/input/file/fingerprint_test.go +++ b/pkg/stanza/operator/input/file/fingerprint_test.go @@ -44,7 +44,8 @@ func TestNewFingerprintDoesNotModifyOffset(t *testing.T) { require.Equal(t, len(fileContents), int(info.Size())) // Set the file descriptors pointer to the beginning of the file - temp.Seek(0, 0) + _, err = temp.Seek(0, 0) + require.NoError(t, err) fp, err := f.NewFingerprint(temp) require.NoError(t, err) diff --git a/pkg/stanza/operator/input/file/rotation_test.go b/pkg/stanza/operator/input/file/rotation_test.go index 26571c7f5477..ff0fda44da4e 100644 --- a/pkg/stanza/operator/input/file/rotation_test.go +++ b/pkg/stanza/operator/input/file/rotation_test.go @@ -60,7 +60,9 @@ func TestMultiFileRotate(t *testing.T) { } require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() temps := make([]*os.File, 0, numFiles) for i := 0; i < numFiles; i++ { @@ -117,7 +119,9 @@ func TestMultiFileRotateSlow(t *testing.T) { } require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() var wg sync.WaitGroup for fileNum := 0; fileNum < numFiles; fileNum++ { @@ -163,7 +167,9 @@ func TestMultiCopyTruncateSlow(t *testing.T) { } require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() var wg sync.WaitGroup for fileNum := 0; fileNum < numFiles; fileNum++ { @@ -260,7 +266,9 @@ func (rt rotationTest) run(tc rotationTest, copyTruncate, sequential bool) func( } require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() for _, message := range expected { logger.Println(message) @@ -353,7 +361,9 @@ func TestMoveFile(t *testing.T) { temp1.Close() operator.poll(context.Background()) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, "testlog1") @@ -379,7 +389,9 @@ func TestTrackMovedAwayFiles(t *testing.T) { temp1.Close() operator.poll(context.Background()) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, "testlog1") @@ -413,13 +425,16 @@ func TestTruncateThenWrite(t *testing.T) { writeString(t, temp1, "testlog1\ntestlog2\n") operator.poll(context.Background()) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, "testlog1") waitForMessage(t, logReceived, "testlog2") require.NoError(t, temp1.Truncate(0)) - temp1.Seek(0, 0) + _, err := temp1.Seek(0, 0) + require.NoError(t, err) writeString(t, temp1, "testlog3\n") operator.poll(context.Background()) @@ -440,7 +455,9 @@ func TestCopyTruncateWriteBoth(t *testing.T) { writeString(t, temp1, "testlog1\ntestlog2\n") operator.poll(context.Background()) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, "testlog1") waitForMessage(t, logReceived, "testlog2") @@ -453,7 +470,8 @@ func TestCopyTruncateWriteBoth(t *testing.T) { // Truncate original file require.NoError(t, temp1.Truncate(0)) - temp1.Seek(0, 0) + _, err = temp1.Seek(0, 0) + require.NoError(t, err) // Write to original and new file writeString(t, temp2, "testlog3\n") @@ -478,7 +496,9 @@ func TestFileMovedWhileOff_BigFiles(t *testing.T) { // Start the operator require.NoError(t, operator.Start(persister)) - defer operator.Stop() + defer func() { + require.NoError(t, operator.Stop()) + }() waitForMessage(t, logReceived, log1) // Stop the operator, then rename and write a new log diff --git a/pkg/stanza/operator/input/generate/generate_test.go b/pkg/stanza/operator/input/generate/generate_test.go index e2508f87d7a7..ff7ca75fb240 100644 --- a/pkg/stanza/operator/input/generate/generate_test.go +++ b/pkg/stanza/operator/input/generate/generate_test.go @@ -40,7 +40,9 @@ func TestInputGenerate(t *testing.T) { require.NoError(t, err) require.NoError(t, op.Start(testutil.NewMockPersister("test"))) - defer op.Stop() + defer func() { + require.NoError(t, op.Stop()) + }() for i := 0; i < 5; i++ { fake.ExpectBody(t, "test message") diff --git a/pkg/stanza/operator/input/journald/journald_test.go b/pkg/stanza/operator/input/journald/journald_test.go index 55bd83385e55..68c8fadab2ed 100644 --- a/pkg/stanza/operator/input/journald/journald_test.go +++ b/pkg/stanza/operator/input/journald/journald_test.go @@ -69,7 +69,9 @@ func TestInputJournald(t *testing.T) { err = op.Start(testutil.NewMockPersister("test")) require.NoError(t, err) - defer op.Stop() + defer func() { + require.NoError(t, op.Stop()) + }() expected := map[string]interface{}{ "_BOOT_ID": "c4fa36de06824d21835c05ff80c54468", diff --git a/pkg/stanza/operator/input/k8sevent/k8s_event_test.go b/pkg/stanza/operator/input/k8sevent/k8s_event_test.go index 5507c931f7e8..b47524896182 100644 --- a/pkg/stanza/operator/input/k8sevent/k8s_event_test.go +++ b/pkg/stanza/operator/input/k8sevent/k8s_event_test.go @@ -83,7 +83,9 @@ func TestWatchNamespace(t *testing.T) { op.OutputOperators = []operator.Operator{fake} op.startWatchingNamespace(ctx, "test_namespace") - defer op.Stop() + defer func() { + require.NoError(t, op.Stop()) + }() select { case e := <-fake.Received: diff --git a/pkg/stanza/operator/input/stdin/stdin_test.go b/pkg/stanza/operator/input/stdin/stdin_test.go index 3ec4588237be..6eb573e38aa2 100644 --- a/pkg/stanza/operator/input/stdin/stdin_test.go +++ b/pkg/stanza/operator/input/stdin/stdin_test.go @@ -32,7 +32,7 @@ func TestStdin(t *testing.T) { require.NoError(t, err) fake := testutil.NewFakeOutput(t) - op.SetOutputs([]operator.Operator{fake}) + require.NoError(t, op.SetOutputs([]operator.Operator{fake})) r, w, err := os.Pipe() require.NoError(t, err) @@ -41,9 +41,12 @@ func TestStdin(t *testing.T) { stdin.stdin = r require.NoError(t, stdin.Start(testutil.NewMockPersister("test"))) - defer stdin.Stop() + defer func() { + require.NoError(t, stdin.Stop()) + }() - w.WriteString("test") + _, err = w.WriteString("test") + require.NoError(t, err) w.Close() fake.ExpectBody(t, "test") } diff --git a/pkg/stanza/operator/input/syslog/syslog_test.go b/pkg/stanza/operator/input/syslog/syslog_test.go index 40c9fbf6410a..76fbcd46b54e 100644 --- a/pkg/stanza/operator/input/syslog/syslog_test.go +++ b/pkg/stanza/operator/input/syslog/syslog_test.go @@ -81,7 +81,9 @@ func SyslogInputTest(t *testing.T, cfg *SyslogInputConfig, tc syslog.Case) { conn.Close() require.NoError(t, err) - defer p.Stop() + defer func() { + require.NoError(t, p.Stop()) + }() select { case e := <-fake.Received: // close pipeline to avoid data race diff --git a/pkg/stanza/operator/input/udp/udp_test.go b/pkg/stanza/operator/input/udp/udp_test.go index b955856bd017..babbef65867e 100644 --- a/pkg/stanza/operator/input/udp/udp_test.go +++ b/pkg/stanza/operator/input/udp/udp_test.go @@ -232,7 +232,9 @@ func BenchmarkUdpInput(b *testing.B) { go func() { conn, err := net.Dial("udp", udpInput.connection.LocalAddr().String()) require.NoError(b, err) - defer udpInput.Stop() + defer func() { + require.NoError(b, udpInput.Stop()) + }() defer conn.Close() message := []byte("message\n") for { diff --git a/pkg/stanza/operator/parser/csv/csv_test.go b/pkg/stanza/operator/parser/csv/csv_test.go index 52a02a30efc8..c5d08299a44c 100644 --- a/pkg/stanza/operator/parser/csv/csv_test.go +++ b/pkg/stanza/operator/parser/csv/csv_test.go @@ -624,7 +624,7 @@ func TestParserCSV(t *testing.T) { require.NoError(t, err) fake := testutil.NewFakeOutput(t) - op.SetOutputs([]operator.Operator{fake}) + require.NoError(t, op.SetOutputs([]operator.Operator{fake})) ots := time.Now() for i, inputEntry := range tc.inputEntries { @@ -863,7 +863,7 @@ cc""",dddd,eeee`, require.NoError(t, err) fake := testutil.NewFakeOutput(t) - op.SetOutputs([]operator.Operator{fake}) + require.NoError(t, op.SetOutputs([]operator.Operator{fake})) entry := entry.New() entry.Body = tc.input @@ -885,7 +885,7 @@ func TestParserCSVInvalidJSONInput(t *testing.T) { require.NoError(t, err) fake := testutil.NewFakeOutput(t) - op.SetOutputs([]operator.Operator{fake}) + require.NoError(t, op.SetOutputs([]operator.Operator{fake})) entry := entry.New() entry.Body = "{\"name\": \"stanza\"}" diff --git a/pkg/stanza/operator/parser/json/json_test.go b/pkg/stanza/operator/parser/json/json_test.go index 911d892503b7..12e5de9d71d8 100644 --- a/pkg/stanza/operator/parser/json/json_test.go +++ b/pkg/stanza/operator/parser/json/json_test.go @@ -159,7 +159,7 @@ func TestJSONParser(t *testing.T) { require.NoError(t, err) fake := testutil.NewFakeOutput(t) - op.SetOutputs([]operator.Operator{fake}) + require.NoError(t, op.SetOutputs([]operator.Operator{fake})) ots := time.Now() tc.input.ObservedTimestamp = ots diff --git a/pkg/stanza/operator/parser/keyvalue/keyvalue_test.go b/pkg/stanza/operator/parser/keyvalue/keyvalue_test.go index d0c77e061691..a21b12b0bbe4 100644 --- a/pkg/stanza/operator/parser/keyvalue/keyvalue_test.go +++ b/pkg/stanza/operator/parser/keyvalue/keyvalue_test.go @@ -532,7 +532,7 @@ func TestKVParser(t *testing.T) { require.NoError(t, err) fake := testutil.NewFakeOutput(t) - op.SetOutputs([]operator.Operator{fake}) + require.NoError(t, op.SetOutputs([]operator.Operator{fake})) ots := time.Now() tc.input.ObservedTimestamp = ots diff --git a/pkg/stanza/operator/parser/regex/regex_test.go b/pkg/stanza/operator/parser/regex/regex_test.go index cc6ede2777a5..9a257dd7aa13 100644 --- a/pkg/stanza/operator/parser/regex/regex_test.go +++ b/pkg/stanza/operator/parser/regex/regex_test.go @@ -149,7 +149,7 @@ func TestParserRegex(t *testing.T) { require.NoError(t, err) fake := testutil.NewFakeOutput(t) - op.SetOutputs([]operator.Operator{fake}) + require.NoError(t, op.SetOutputs([]operator.Operator{fake})) ots := time.Now() tc.input.ObservedTimestamp = ots diff --git a/pkg/stanza/operator/parser/severity/severity_test.go b/pkg/stanza/operator/parser/severity/severity_test.go index dde62583fc9a..97eb422c8359 100644 --- a/pkg/stanza/operator/parser/severity/severity_test.go +++ b/pkg/stanza/operator/parser/severity/severity_test.go @@ -222,11 +222,11 @@ func TestSeverityParser(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { rootCfg := parseSeverityTestConfig(rootField, tc.mappingSet, tc.mapping) - rootEntry := makeTestEntry(rootField, tc.sample) + rootEntry := makeTestEntry(t, rootField, tc.sample) t.Run("root", runSeverityParseTest(rootCfg, rootEntry, tc.buildErr, tc.parseErr, tc.expected)) nonRootCfg := parseSeverityTestConfig(someField, tc.mappingSet, tc.mapping) - nonRootEntry := makeTestEntry(someField, tc.sample) + nonRootEntry := makeTestEntry(t, someField, tc.sample) t.Run("non-root", runSeverityParseTest(nonRootCfg, nonRootEntry, tc.buildErr, tc.parseErr, tc.expected)) }) } @@ -272,9 +272,9 @@ func parseSeverityTestConfig(parseFrom entry.Field, preset string, mapping map[i return cfg } -func makeTestEntry(field entry.Field, value interface{}) *entry.Entry { +func makeTestEntry(t *testing.T, field entry.Field, value interface{}) *entry.Entry { e := entry.New() - e.Set(field, value) + require.NoError(t, e.Set(field, value)) return e } diff --git a/pkg/stanza/operator/parser/time/time_test.go b/pkg/stanza/operator/parser/time/time_test.go index 525d588aaeac..959aa740fbb2 100644 --- a/pkg/stanza/operator/parser/time/time_test.go +++ b/pkg/stanza/operator/parser/time/time_test.go @@ -264,16 +264,16 @@ func TestTimeParser(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { gotimeRootCfg := parseTimeTestConfig(helper.GotimeKey, tc.gotimeLayout, rootField) - t.Run("gotime-root", runTimeParseTest(t, gotimeRootCfg, makeTestEntry(rootField, tc.sample), false, false, tc.expected)) + t.Run("gotime-root", runTimeParseTest(t, gotimeRootCfg, makeTestEntry(t, rootField, tc.sample), false, false, tc.expected)) gotimeNonRootCfg := parseTimeTestConfig(helper.GotimeKey, tc.gotimeLayout, someField) - t.Run("gotime-non-root", runTimeParseTest(t, gotimeNonRootCfg, makeTestEntry(someField, tc.sample), false, false, tc.expected)) + t.Run("gotime-non-root", runTimeParseTest(t, gotimeNonRootCfg, makeTestEntry(t, someField, tc.sample), false, false, tc.expected)) strptimeRootCfg := parseTimeTestConfig(helper.StrptimeKey, tc.strptimeLayout, rootField) - t.Run("strptime-root", runTimeParseTest(t, strptimeRootCfg, makeTestEntry(rootField, tc.sample), false, false, tc.expected)) + t.Run("strptime-root", runTimeParseTest(t, strptimeRootCfg, makeTestEntry(t, rootField, tc.sample), false, false, tc.expected)) strptimeNonRootCfg := parseTimeTestConfig(helper.StrptimeKey, tc.strptimeLayout, someField) - t.Run("strptime-non-root", runTimeParseTest(t, strptimeNonRootCfg, makeTestEntry(someField, tc.sample), false, false, tc.expected)) + t.Run("strptime-non-root", runTimeParseTest(t, strptimeNonRootCfg, makeTestEntry(t, someField, tc.sample), false, false, tc.expected)) }) } } @@ -431,10 +431,10 @@ func TestTimeEpochs(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { rootCfg := parseTimeTestConfig(helper.EpochKey, tc.layout, rootField) - t.Run("epoch-root", runLossyTimeParseTest(t, rootCfg, makeTestEntry(rootField, tc.sample), false, false, tc.expected, tc.maxLoss)) + t.Run("epoch-root", runLossyTimeParseTest(t, rootCfg, makeTestEntry(t, rootField, tc.sample), false, false, tc.expected, tc.maxLoss)) nonRootCfg := parseTimeTestConfig(helper.EpochKey, tc.layout, someField) - t.Run("epoch-non-root", runLossyTimeParseTest(t, nonRootCfg, makeTestEntry(someField, tc.sample), false, false, tc.expected, tc.maxLoss)) + t.Run("epoch-non-root", runLossyTimeParseTest(t, nonRootCfg, makeTestEntry(t, someField, tc.sample), false, false, tc.expected, tc.maxLoss)) }) } } @@ -493,17 +493,17 @@ func TestTimeErrors(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { rootCfg := parseTimeTestConfig(tc.layoutType, tc.layout, rootField) - t.Run("err-root", runTimeParseTest(t, rootCfg, makeTestEntry(rootField, tc.sample), tc.buildErr, tc.parseErr, time.Now())) + t.Run("err-root", runTimeParseTest(t, rootCfg, makeTestEntry(t, rootField, tc.sample), tc.buildErr, tc.parseErr, time.Now())) nonRootCfg := parseTimeTestConfig(tc.layoutType, tc.layout, someField) - t.Run("err-non-root", runTimeParseTest(t, nonRootCfg, makeTestEntry(someField, tc.sample), tc.buildErr, tc.parseErr, time.Now())) + t.Run("err-non-root", runTimeParseTest(t, nonRootCfg, makeTestEntry(t, someField, tc.sample), tc.buildErr, tc.parseErr, time.Now())) }) } } -func makeTestEntry(field entry.Field, value interface{}) *entry.Entry { +func makeTestEntry(t *testing.T, field entry.Field, value interface{}) *entry.Entry { e := entry.New() - e.Set(field, value) + require.NoError(t, e.Set(field, value)) return e } diff --git a/pkg/stanza/operator/transformer/add/add_test.go b/pkg/stanza/operator/transformer/add/add_test.go index 0fe94c2868b7..2566f15a721a 100644 --- a/pkg/stanza/operator/transformer/add/add_test.go +++ b/pkg/stanza/operator/transformer/add/add_test.go @@ -319,7 +319,7 @@ func TestProcessAndBuild(t *testing.T) { add := op.(*AddOperator) fake := testutil.NewFakeOutput(t) - add.SetOutputs([]operator.Operator{fake}) + require.NoError(t, add.SetOutputs([]operator.Operator{fake})) val := tc.input() err = add.Process(context.Background(), val) if tc.expectErr { diff --git a/pkg/stanza/operator/transformer/copy/copy_test.go b/pkg/stanza/operator/transformer/copy/copy_test.go index 1cb7083d3404..0fe74adf24cb 100644 --- a/pkg/stanza/operator/transformer/copy/copy_test.go +++ b/pkg/stanza/operator/transformer/copy/copy_test.go @@ -303,7 +303,7 @@ func TestBuildAndProcess(t *testing.T) { copy := op.(*CopyOperator) fake := testutil.NewFakeOutput(t) - copy.SetOutputs([]operator.Operator{fake}) + require.NoError(t, copy.SetOutputs([]operator.Operator{fake})) val := tc.input() err = copy.Process(context.Background(), val) if tc.expectErr { diff --git a/pkg/stanza/operator/transformer/flatten/flatten_test.go b/pkg/stanza/operator/transformer/flatten/flatten_test.go index 5d0b1f7efff6..573b6b17c8ae 100644 --- a/pkg/stanza/operator/transformer/flatten/flatten_test.go +++ b/pkg/stanza/operator/transformer/flatten/flatten_test.go @@ -280,7 +280,7 @@ func TestBuildAndProcess(t *testing.T) { flatten := op.(*FlattenOperator) fake := testutil.NewFakeOutput(t) - flatten.SetOutputs([]operator.Operator{fake}) + require.NoError(t, flatten.SetOutputs([]operator.Operator{fake})) val := tc.input() err = flatten.Process(context.Background(), val) diff --git a/pkg/stanza/operator/transformer/move/move_test.go b/pkg/stanza/operator/transformer/move/move_test.go index 8f706faefc75..7c5f995d0546 100644 --- a/pkg/stanza/operator/transformer/move/move_test.go +++ b/pkg/stanza/operator/transformer/move/move_test.go @@ -518,7 +518,7 @@ func TestProcessAndBuild(t *testing.T) { move := op.(*MoveOperator) fake := testutil.NewFakeOutput(t) - move.SetOutputs([]operator.Operator{fake}) + require.NoError(t, move.SetOutputs([]operator.Operator{fake})) val := tc.input() err = move.Process(context.Background(), val) if tc.expectErr { diff --git a/pkg/stanza/operator/transformer/noop/noop_test.go b/pkg/stanza/operator/transformer/noop/noop_test.go index 3d745a2dd301..a9f5a3661a70 100644 --- a/pkg/stanza/operator/transformer/noop/noop_test.go +++ b/pkg/stanza/operator/transformer/noop/noop_test.go @@ -46,7 +46,7 @@ func TestProcess(t *testing.T) { require.NoError(t, err) fake := testutil.NewFakeOutput(t) - op.SetOutputs([]operator.Operator{fake}) + require.NoError(t, op.SetOutputs([]operator.Operator{fake})) entry := entry.New() entry.AddAttribute("label", "value") diff --git a/pkg/stanza/operator/transformer/recombine/recombine_test.go b/pkg/stanza/operator/transformer/recombine/recombine_test.go index 60a758de5280..515aac45de14 100644 --- a/pkg/stanza/operator/transformer/recombine/recombine_test.go +++ b/pkg/stanza/operator/transformer/recombine/recombine_test.go @@ -298,7 +298,7 @@ func TestRecombineOperator(t *testing.T) { require.NoError(t, err) for _, e := range tc.input { - recombine.Process(context.Background(), e) + require.NoError(t, recombine.Process(context.Background(), e)) } for _, expected := range tc.expectedOutput { @@ -327,7 +327,7 @@ func TestRecombineOperator(t *testing.T) { require.NoError(t, err) // Send an entry that isn't the last in a multiline - recombine.Process(context.Background(), entry.New()) + require.NoError(t, recombine.Process(context.Background(), entry.New())) // Ensure that the entry isn't immediately sent select { @@ -337,7 +337,7 @@ func TestRecombineOperator(t *testing.T) { } // Stop the operator - recombine.Stop() + require.NoError(t, recombine.Stop()) // Ensure that the entries in the buffer are flushed select { @@ -359,7 +359,7 @@ func BenchmarkRecombine(b *testing.B) { fake := testutil.NewFakeOutput(b) require.NoError(b, recombine.SetOutputs([]operator.Operator{fake})) - recombine.Start(nil) + require.NoError(b, recombine.Start(nil)) go func() { for { @@ -404,7 +404,7 @@ func TestTimeout(t *testing.T) { ctx := context.Background() - recombine.Start(nil) + require.NoError(t, recombine.Start(nil)) require.NoError(t, recombine.Process(ctx, e)) select { case <-fake.Received: diff --git a/pkg/stanza/operator/transformer/remove/remove_test.go b/pkg/stanza/operator/transformer/remove/remove_test.go index 3d451250cbd0..0c5e32eda58d 100644 --- a/pkg/stanza/operator/transformer/remove/remove_test.go +++ b/pkg/stanza/operator/transformer/remove/remove_test.go @@ -268,7 +268,7 @@ func TestProcessAndBuild(t *testing.T) { remove := op.(*RemoveOperator) fake := testutil.NewFakeOutput(t) - remove.SetOutputs([]operator.Operator{fake}) + require.NoError(t, remove.SetOutputs([]operator.Operator{fake})) val := tc.input() err = remove.Process(context.Background(), val) if tc.expectErr { diff --git a/pkg/stanza/operator/transformer/retain/retain_test.go b/pkg/stanza/operator/transformer/retain/retain_test.go index 62ddfe73d8a6..524734f2545a 100644 --- a/pkg/stanza/operator/transformer/retain/retain_test.go +++ b/pkg/stanza/operator/transformer/retain/retain_test.go @@ -400,7 +400,7 @@ func TestBuildAndProcess(t *testing.T) { retain := op.(*RetainOperator) fake := testutil.NewFakeOutput(t) - retain.SetOutputs([]operator.Operator{fake}) + require.NoError(t, retain.SetOutputs([]operator.Operator{fake})) val := tc.input() err = retain.Process(context.Background(), val) if tc.expectErr {