Skip to content

Commit 471744c

Browse files
committed
Address lint errors
1 parent bb576f7 commit 471744c

File tree

3 files changed

+7
-82
lines changed

3 files changed

+7
-82
lines changed

pkg/sources/filesystem/filesystem_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -252,52 +252,6 @@ func TestEnumerateReporterErr(t *testing.T) {
252252
s := Source{}
253253
err = s.Init(ctx, "test enumerate", 0, 0, true, conn, 1)
254254
assert.NoError(t, err)
255-
256-
// Enumerate should always return an error if the reporter returns an
257-
// error.
258-
reporter := sourcestest.ErrReporter{}
259-
err = s.Enumerate(ctx, &reporter)
260-
assert.Error(t, err)
261-
}
262-
263-
func TestChunkUnitReporterErr(t *testing.T) {
264-
t.Parallel()
265-
ctx := context.Background()
266-
267-
// Setup test file to chunk.
268-
tmpfile, err := os.CreateTemp("", "example.txt")
269-
if err != nil {
270-
t.Fatal(err)
271-
}
272-
defer os.Remove(tmpfile.Name())
273-
274-
fileContents := []byte("TestChunkUnit")
275-
_, err = tmpfile.Write(fileContents)
276-
assert.NoError(t, err)
277-
assert.NoError(t, tmpfile.Close())
278-
279-
conn, err := anypb.New(&sourcespb.Filesystem{})
280-
assert.NoError(t, err)
281-
282-
// Initialize the source.
283-
s := Source{}
284-
err = s.Init(ctx, "test chunk unit", 0, 0, true, conn, 1)
285-
assert.NoError(t, err)
286-
287-
// Happy path. ChunkUnit should always return an error if the reporter
288-
// returns an error.
289-
reporter := sourcestest.ErrReporter{}
290-
err = s.ChunkUnit(ctx, sources.CommonSourceUnit{
291-
ID: tmpfile.Name(),
292-
}, &reporter)
293-
assert.Error(t, err)
294-
295-
// Error path. ChunkUnit should always return an error if the reporter
296-
// returns an error.
297-
err = s.ChunkUnit(ctx, sources.CommonSourceUnit{
298-
ID: "/file/not/found",
299-
}, &reporter)
300-
assert.Error(t, err)
301255
}
302256

303257
// createTempFile is a helper function to create a temporary file in the given

pkg/sources/github/github_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,9 @@ func TestEnumerate(t *testing.T) {
606606

607607
var reportedRepos []string
608608
reporter := sources.VisitorReporter{
609-
VisitUnit: func(ctx context.Context, su sources.SourceUnit) error {
609+
VisitUnit: func(ctx context.Context, su sources.SourceUnit) {
610610
url, _ := su.SourceUnitID()
611611
reportedRepos = append(reportedRepos, url)
612-
return nil
613612
},
614613
}
615614

@@ -961,8 +960,6 @@ func Test_ScanMultipleTargets_MultipleErrors(t *testing.T) {
961960

962961
func noopReporter() sources.UnitReporter {
963962
return sources.VisitorReporter{
964-
VisitUnit: func(context.Context, sources.SourceUnit) error {
965-
return nil
966-
},
963+
VisitUnit: func(context.Context, sources.SourceUnit) {},
967964
}
968965
}

pkg/sourcestest/sourcestest.go

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package sourcestest
22

33
import (
4-
"fmt"
5-
64
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
75
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
86
)
@@ -12,10 +10,7 @@ type reporter interface {
1210
sources.ChunkReporter
1311
}
1412

15-
var (
16-
_ reporter = (*TestReporter)(nil)
17-
_ reporter = (*ErrReporter)(nil)
18-
)
13+
var _ reporter = (*TestReporter)(nil)
1914

2015
// TestReporter is a helper struct that implements both UnitReporter and
2116
// ChunkReporter by simply recording the values passed in the methods.
@@ -26,36 +21,15 @@ type TestReporter struct {
2621
ChunkErrs []error
2722
}
2823

29-
func (t *TestReporter) UnitOk(_ context.Context, unit sources.SourceUnit) error {
24+
func (t *TestReporter) UnitOk(_ context.Context, unit sources.SourceUnit) {
3025
t.Units = append(t.Units, unit)
31-
return nil
3226
}
33-
func (t *TestReporter) UnitErr(_ context.Context, err error) error {
27+
func (t *TestReporter) UnitErr(_ context.Context, err error) {
3428
t.UnitErrs = append(t.UnitErrs, err)
35-
return nil
3629
}
37-
func (t *TestReporter) ChunkOk(_ context.Context, chunk sources.Chunk) error {
30+
func (t *TestReporter) ChunkOk(_ context.Context, chunk sources.Chunk) {
3831
t.Chunks = append(t.Chunks, chunk)
39-
return nil
4032
}
41-
func (t *TestReporter) ChunkErr(_ context.Context, err error) error {
33+
func (t *TestReporter) ChunkErr(_ context.Context, err error) {
4234
t.ChunkErrs = append(t.ChunkErrs, err)
43-
return nil
44-
}
45-
46-
// ErrReporter implements UnitReporter and ChunkReporter but always returns an
47-
// error.
48-
type ErrReporter struct{}
49-
50-
func (ErrReporter) UnitOk(context.Context, sources.SourceUnit) error {
51-
return fmt.Errorf("ErrReporter: UnitOk error")
52-
}
53-
func (ErrReporter) UnitErr(context.Context, error) error {
54-
return fmt.Errorf("ErrReporter: UnitErr error")
55-
}
56-
func (ErrReporter) ChunkOk(context.Context, sources.Chunk) error {
57-
return fmt.Errorf("ErrReporter: ChunkOk error")
58-
}
59-
func (ErrReporter) ChunkErr(context.Context, error) error {
60-
return fmt.Errorf("ErrReporter: ChunkErr error")
6135
}

0 commit comments

Comments
 (0)