@@ -30,6 +30,7 @@ import (
30
30
"testing"
31
31
"time"
32
32
33
+ "github.com/stretchr/testify/assert"
33
34
"github.com/stretchr/testify/require"
34
35
35
36
loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
@@ -241,33 +242,26 @@ func (e *inputTestingEnvironment) requireRegistryEntryCount(expectedCount int) {
241
242
// requireOffsetInRegistry checks if the expected offset is set for a file.
242
243
func (e * inputTestingEnvironment ) requireOffsetInRegistry (filename , inputID string , expectedOffset int ) {
243
244
e .t .Helper ()
244
- var offsetStr strings.Builder
245
+ require .EventuallyWithT (e .t , func (ct * assert.CollectT ) {
246
+ var offsetStr strings.Builder
245
247
246
- filepath := e .abspath (filename )
247
- fi , err := os .Stat (filepath )
248
- if err != nil {
249
- e .t .Fatalf ("cannot stat file when cheking for offset: %+v" , err )
250
- }
248
+ filepath := e .abspath (filename )
249
+ fi , err := os .Stat (filepath )
250
+ assert .NoError (ct , err , "cannot stat file when checking for offset" )
251
251
252
- id := getIDFromPath (filepath , inputID , fi )
253
- var entry registryEntry
254
- require .Eventuallyf (e .t , func () bool {
252
+ id := getIDFromPath (filepath , inputID , fi )
253
+ var entry registryEntry
255
254
offsetStr .Reset ()
256
255
257
256
entry , err = e .getRegistryState (id )
258
- if err != nil {
259
- e .t .Fatalf ("could not get state for '%s' from registry, err: %s" , id , err )
260
- }
257
+ assert .NoError (ct , err , "error getting state for ID '%s' from the registry" , id )
261
258
262
259
fmt .Fprint (& offsetStr , entry .Cursor .Offset )
263
-
264
- return expectedOffset == entry .Cursor .Offset
260
+ assert .Equal (ct , expectedOffset , entry .Cursor .Offset , "expected offset does not match" )
265
261
},
266
262
10 * time .Second ,
267
263
100 * time .Millisecond ,
268
- "expected offset: '%d', cursor offset: '%s'" ,
269
- expectedOffset ,
270
- & offsetStr )
264
+ "failed to get expected registry offset" )
271
265
}
272
266
273
267
// requireMetaInRegistry checks if the expected metadata is saved to the registry.
0 commit comments