Skip to content

Commit

Permalink
update test to use sourcestest
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-decker committed Oct 16, 2023
1 parent c99e0b9 commit ec3c59d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
4 changes: 2 additions & 2 deletions pkg/sources/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package sources

import (
"errors"
"fmt"
"reflect"
"sync"
"testing"
)
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestNewScanErrors(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
got := NewScanErrors()

if !reflect.DeepEqual(got, tc.want) {
if !errors.Is(got.Errors(), tc.want.Errors()) {
t.Errorf("got %+v, want %+v", got, tc.want)
}
})
Expand Down
26 changes: 0 additions & 26 deletions pkg/sources/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"errors"
"fmt"
"time"

"github.com/trufflesecurity/trufflehog/v3/pkg/context"
)

type ChunkFunc func(chunk *Chunk) error
Expand All @@ -29,27 +27,3 @@ func HandleTestChannel(chunksCh chan *Chunk, cf ChunkFunc) error {
}
}
}

type TestReporter struct {
Units []SourceUnit
UnitErrs []error
Chunks []Chunk
ChunkErrs []error
}

func (t *TestReporter) UnitOk(_ context.Context, unit SourceUnit) error {
t.Units = append(t.Units, unit)
return nil
}
func (t *TestReporter) UnitErr(_ context.Context, err error) error {
t.UnitErrs = append(t.UnitErrs, err)
return nil
}
func (t *TestReporter) ChunkOk(_ context.Context, chunk Chunk) error {
t.Chunks = append(t.Chunks, chunk)
return nil
}
func (t *TestReporter) ChunkErr(_ context.Context, err error) error {
t.ChunkErrs = append(t.ChunkErrs, err)
return nil
}
6 changes: 2 additions & 4 deletions pkg/sources/travisci/travisci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
"github.com/trufflesecurity/trufflehog/v3/pkg/sourcestest"
)

func TestSource_Scan(t *testing.T) {
// ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
// defer cancel()
ctx := context.Background()

secret, err := common.GetTestSecret(ctx)
Expand Down Expand Up @@ -76,7 +74,7 @@ func TestSource_Scan(t *testing.T) {
t.Fatalf("Source.Init() error = %v, wantErr %v", err, tt.wantErr)
}

reporter := sources.TestReporter{}
reporter := sourcestest.TestReporter{}
s.returnAfterFirstChunk = true

err = s.Enumerate(ctx, &reporter)
Expand Down

0 comments on commit ec3c59d

Please sign in to comment.