trufflehog/pkg/sources/test_helpers.go
ahrav dcc102a81c
[Thog-371] Utilize config struct for engine scans (#700)
* Use a config struct when scanning and engine source.

* fix tests.

* Move test_helpers to the sources pkg.

* Handle ScanGit error in tests.

* adderss comments.

* Use functional options.

* Remove temp var.

* Add better var names for the setup functions for each config.

* Remove unused var.

* fix error logs.

* fix error logs.

* single line.

* remove blank lines.
2022-08-10 10:11:13 -07:00

29 lines
507 B
Go

package sources
import (
"errors"
"fmt"
"time"
)
type ChunkFunc func(chunk *Chunk) error
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):
return fmt.Errorf("no new chunks recieved after 10 seconds")
}
}
}