Skip to content

Find, verify, and analyze leaked credentials

Implement String for ScanErrors (#1131)

Miccahd2d03426ed90
diff --git a/pkg/sources/errors.go b/pkg/sources/errors.go
index 0d73338d1..01e464e44 100644
--- a/pkg/sources/errors.go
+++ b/pkg/sources/errors.go
@@ -1,6 +1,7 @@
package sources
import (
+ "fmt"
"sync"
)
@@ -29,3 +30,7 @@ func (s *ScanErrors) Count() uint64 {
defer s.mu.RUnlock()
return uint64(len(s.errors))
}
+
+func (s *ScanErrors) String() string {
+ return fmt.Sprintf("%v", s.errors)
+}
diff --git a/pkg/sources/errors_test.go b/pkg/sources/errors_test.go
index 30334cdc9..6d12f02f2 100644
--- a/pkg/sources/errors_test.go
+++ b/pkg/sources/errors_test.go
@@ -1,6 +1,7 @@
package sources
import (
+ "fmt"
"reflect"
"sync"
"testing"
@@ -147,3 +148,12 @@ func TestScanErrorsCount(t *testing.T) {
})
}
}
+
+func TestScanErrorsString(t *testing.T) {
+ se := NewScanErrors()
+ se.Add(nil)
+ want := "[<nil>]"
+ if got := fmt.Sprintf("%v", se); got != want {
+ t.Errorf("got %q, want %q", got, want)
+ }
+}