trufflehog/pkg/handlers/default_test.go
ahrav ebfbd21707
[bug]- Invalid Seek for Non-Seekable Readers (#3095)
* inital work

* fix and add tests

* uncomment

* fix seek end

* use buffer pool

* revert timeout

* make linter happy

* More linting :()
2024-07-24 19:08:56 -07:00

36 lines
712 B
Go

package handlers
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
)
func TestHandleNonArchiveFile(t *testing.T) {
file, err := os.Open("testdata/nonarchive.txt")
assert.Nil(t, err)
defer file.Close()
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
rdr, err := newFileReader(file)
assert.NoError(t, err)
defer rdr.Close()
handler := newDefaultHandler(defaultHandlerType)
archiveChan, err := handler.HandleFile(context.AddLogger(ctx), rdr)
assert.NoError(t, err)
wantChunkCount := 6
count := 0
for range archiveChan {
count++
}
assert.Equal(t, wantChunkCount, count)
}