Skip to content

Commit

Permalink
[chore] Use assert/assert instead of require/assert (#35182)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanotti authored Sep 13, 2024
1 parent 616d91a commit c52a9a7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions receiver/windowseventlogreceiver/receiver_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func TestReadWindowsEventLogger(t *testing.T) {
err = logger.Info(10, logMessage)
require.NoError(t, err)

records := requireExpectedLogRecords(t, sink, src, 1)
records := assertExpectedLogRecords(t, sink, src, 1)
require.Len(t, records, 1)
record := records[0]
body := record.Body().Map().AsRaw()

Expand Down Expand Up @@ -205,7 +206,8 @@ func TestReadWindowsEventLoggerRaw(t *testing.T) {
err = logger.Info(10, logMessage)
require.NoError(t, err)

records := requireExpectedLogRecords(t, sink, src, 1)
records := assertExpectedLogRecords(t, sink, src, 1)
require.Len(t, records, 1)
record := records[0]
body := record.Body().AsString()
bodyStruct := struct {
Expand Down Expand Up @@ -272,8 +274,8 @@ func TestExcludeProvider(t *testing.T) {
require.NoError(t, err)
}

records := requireExpectedLogRecords(t, sink, notExcludedSrc, 1)
assert.NotEmpty(t, records)
records := assertExpectedLogRecords(t, sink, notExcludedSrc, 1)
assert.Len(t, records, 1)

records = filterAllLogRecordsBySource(t, sink, excludedSrc)
assert.Empty(t, records)
Expand Down Expand Up @@ -319,13 +321,13 @@ func assertEventSourceInstallation(t *testing.T, src string) (uninstallEventSour
return
}

func requireExpectedLogRecords(t *testing.T, sink *consumertest.LogsSink, expectedEventSrc string, expectedEventCount int) []plog.LogRecord {
func assertExpectedLogRecords(t *testing.T, sink *consumertest.LogsSink, expectedEventSrc string, expectedEventCount int) []plog.LogRecord {
var actualLogRecords []plog.LogRecord

// logs sometimes take a while to be written, so a substantial wait buffer is needed
require.EventuallyWithT(t, func(c *assert.CollectT) {
assert.EventuallyWithT(t, func(c *assert.CollectT) {
actualLogRecords = filterAllLogRecordsBySource(t, sink, expectedEventSrc)
require.Len(c, actualLogRecords, expectedEventCount)
assert.Len(c, actualLogRecords, expectedEventCount)
}, 10*time.Second, 250*time.Millisecond)

return actualLogRecords
Expand Down

0 comments on commit c52a9a7

Please sign in to comment.