Address lint errors
This commit is contained in:
@@ -252,52 +252,6 @@ func TestEnumerateReporterErr(t *testing.T) {
|
||||
s := Source{}
|
||||
err = s.Init(ctx, "test enumerate", 0, 0, true, conn, 1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Enumerate should always return an error if the reporter returns an
|
||||
// error.
|
||||
reporter := sourcestest.ErrReporter{}
|
||||
err = s.Enumerate(ctx, &reporter)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestChunkUnitReporterErr(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
// Setup test file to chunk.
|
||||
tmpfile, err := os.CreateTemp("", "example.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(tmpfile.Name())
|
||||
|
||||
fileContents := []byte("TestChunkUnit")
|
||||
_, err = tmpfile.Write(fileContents)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tmpfile.Close())
|
||||
|
||||
conn, err := anypb.New(&sourcespb.Filesystem{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Initialize the source.
|
||||
s := Source{}
|
||||
err = s.Init(ctx, "test chunk unit", 0, 0, true, conn, 1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Happy path. ChunkUnit should always return an error if the reporter
|
||||
// returns an error.
|
||||
reporter := sourcestest.ErrReporter{}
|
||||
err = s.ChunkUnit(ctx, sources.CommonSourceUnit{
|
||||
ID: tmpfile.Name(),
|
||||
}, &reporter)
|
||||
assert.Error(t, err)
|
||||
|
||||
// Error path. ChunkUnit should always return an error if the reporter
|
||||
// returns an error.
|
||||
err = s.ChunkUnit(ctx, sources.CommonSourceUnit{
|
||||
ID: "/file/not/found",
|
||||
}, &reporter)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
// createTempFile is a helper function to create a temporary file in the given
|
||||
|
||||
@@ -606,10 +606,9 @@ func TestEnumerate(t *testing.T) {
|
||||
|
||||
var reportedRepos []string
|
||||
reporter := sources.VisitorReporter{
|
||||
VisitUnit: func(ctx context.Context, su sources.SourceUnit) error {
|
||||
VisitUnit: func(ctx context.Context, su sources.SourceUnit) {
|
||||
url, _ := su.SourceUnitID()
|
||||
reportedRepos = append(reportedRepos, url)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@@ -961,8 +960,6 @@ func Test_ScanMultipleTargets_MultipleErrors(t *testing.T) {
|
||||
|
||||
func noopReporter() sources.UnitReporter {
|
||||
return sources.VisitorReporter{
|
||||
VisitUnit: func(context.Context, sources.SourceUnit) error {
|
||||
return nil
|
||||
},
|
||||
VisitUnit: func(context.Context, sources.SourceUnit) {},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package sourcestest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
|
||||
)
|
||||
@@ -12,10 +10,7 @@ type reporter interface {
|
||||
sources.ChunkReporter
|
||||
}
|
||||
|
||||
var (
|
||||
_ reporter = (*TestReporter)(nil)
|
||||
_ reporter = (*ErrReporter)(nil)
|
||||
)
|
||||
var _ reporter = (*TestReporter)(nil)
|
||||
|
||||
// TestReporter is a helper struct that implements both UnitReporter and
|
||||
// ChunkReporter by simply recording the values passed in the methods.
|
||||
@@ -26,36 +21,15 @@ type TestReporter struct {
|
||||
ChunkErrs []error
|
||||
}
|
||||
|
||||
func (t *TestReporter) UnitOk(_ context.Context, unit sources.SourceUnit) error {
|
||||
func (t *TestReporter) UnitOk(_ context.Context, unit sources.SourceUnit) {
|
||||
t.Units = append(t.Units, unit)
|
||||
return nil
|
||||
}
|
||||
func (t *TestReporter) UnitErr(_ context.Context, err error) error {
|
||||
func (t *TestReporter) UnitErr(_ context.Context, err error) {
|
||||
t.UnitErrs = append(t.UnitErrs, err)
|
||||
return nil
|
||||
}
|
||||
func (t *TestReporter) ChunkOk(_ context.Context, chunk sources.Chunk) error {
|
||||
func (t *TestReporter) ChunkOk(_ context.Context, chunk sources.Chunk) {
|
||||
t.Chunks = append(t.Chunks, chunk)
|
||||
return nil
|
||||
}
|
||||
func (t *TestReporter) ChunkErr(_ context.Context, err error) error {
|
||||
func (t *TestReporter) ChunkErr(_ context.Context, err error) {
|
||||
t.ChunkErrs = append(t.ChunkErrs, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ErrReporter implements UnitReporter and ChunkReporter but always returns an
|
||||
// error.
|
||||
type ErrReporter struct{}
|
||||
|
||||
func (ErrReporter) UnitOk(context.Context, sources.SourceUnit) error {
|
||||
return fmt.Errorf("ErrReporter: UnitOk error")
|
||||
}
|
||||
func (ErrReporter) UnitErr(context.Context, error) error {
|
||||
return fmt.Errorf("ErrReporter: UnitErr error")
|
||||
}
|
||||
func (ErrReporter) ChunkOk(context.Context, sources.Chunk) error {
|
||||
return fmt.Errorf("ErrReporter: ChunkOk error")
|
||||
}
|
||||
func (ErrReporter) ChunkErr(context.Context, error) error {
|
||||
return fmt.Errorf("ErrReporter: ChunkErr error")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user