@@ -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"
@@ -229,33 +230,26 @@ func (e *inputTestingEnvironment) requireRegistryEntryCount(expectedCount int) {
229
230
// requireOffsetInRegistry checks if the expected offset is set for a file.
230
231
func (e * inputTestingEnvironment ) requireOffsetInRegistry (filename , inputID string , expectedOffset int ) {
231
232
e .t .Helper ()
232
- var offsetStr strings.Builder
233
+ require .EventuallyWithT (e .t , func (ct * assert.CollectT ) {
234
+ var offsetStr strings.Builder
233
235
234
- filepath := e .abspath (filename )
235
- fi , err := os .Stat (filepath )
236
- if err != nil {
237
- e .t .Fatalf ("cannot stat file when cheking for offset: %+v" , err )
238
- }
236
+ filepath := e .abspath (filename )
237
+ fi , err := os .Stat (filepath )
238
+ assert .NoError (ct , err , "cannot stat file when checking for offset" )
239
239
240
- id := getIDFromPath (filepath , inputID , fi )
241
- var entry registryEntry
242
- require .Eventuallyf (e .t , func () bool {
240
+ id := getIDFromPath (filepath , inputID , fi )
241
+ var entry registryEntry
243
242
offsetStr .Reset ()
244
243
245
244
entry , err = e .getRegistryState (id )
246
- if err != nil {
247
- e .t .Fatalf ("could not get state for '%s' from registry, err: %s" , id , err )
248
- }
245
+ assert .NoError (ct , err , "error getting state for ID '%s' from the registry" , id )
249
246
250
247
fmt .Fprint (& offsetStr , entry .Cursor .Offset )
251
-
252
- return expectedOffset == entry .Cursor .Offset
248
+ assert .Equal (ct , expectedOffset , entry .Cursor .Offset , "expected offset does not match" )
253
249
},
254
250
10 * time .Second ,
255
251
100 * time .Millisecond ,
256
- "expected offset: '%d', cursor offset: '%s'" ,
257
- expectedOffset ,
258
- & offsetStr )
252
+ "failed to get expected registry offset" )
259
253
}
260
254
261
255
// requireMetaInRegistry checks if the expected metadata is saved to the registry.
0 commit comments