trufflehog/pkg/sources/test_helpers.go

30 lines
507 B
Go
Raw Normal View History

package sources
import (
"errors"
"fmt"
"time"
)
type ChunkFunc func(chunk *Chunk) error
2022-02-16 01:38:19 +00:00
var MatchError = errors.New("chunk doesn't match")
func HandleTestChannel(chunksCh chan *Chunk, cf ChunkFunc) error {
for {
select {
case gotChunk := <-chunksCh:
err := cf(gotChunk)
if err != nil {
if errors.Is(err, MatchError) {
continue
}
return err
}
return nil
case <-time.After(10 * time.Second):
2023-01-25 16:57:39 +00:00
return fmt.Errorf("no new chunks received after 10 seconds")
}
}
}