refactor: change detect tests to t.Fatal instead of log.Fatal (#1270)

This commit is contained in:
Oleksandr Redko authored and GitHub committed 2023-09-20 13:46:35 -05:00
1 parent d9f86d6123
commit 14b1ca9fd9
1 file changed
+5 -6
+5 -6
View File
@@ -6,7 +6,6 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/rs/zerolog/log"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -479,7 +478,7 @@ func TestFromGit(t *testing.T) {
var ignorePath string var ignorePath string
info, err := os.Stat(tt.source) info, err := os.Stat(tt.source)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore") t.Fatalf("could not os.Stat: %v", err)
} }
if info.IsDir() { if info.IsDir() {
@@ -488,7 +487,7 @@ func TestFromGit(t *testing.T) {
ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore") ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore")
} }
if err = detector.AddGitleaksIgnore(ignorePath); err != nil { if err = detector.AddGitleaksIgnore(ignorePath); err != nil {
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore") t.Fatalf("could not call AddGitleaksIgnore: %v", err)
} }
findings, err := detector.DetectGit(tt.source, tt.logOpts, DetectType) findings, err := detector.DetectGit(tt.source, tt.logOpts, DetectType)
@@ -572,7 +571,7 @@ func TestFromGitStaged(t *testing.T) {
} }
detector := NewDetector(cfg) detector := NewDetector(cfg)
if err = detector.AddGitleaksIgnore(filepath.Join(tt.source, ".gitleaksignore")); err != nil { if err = detector.AddGitleaksIgnore(filepath.Join(tt.source, ".gitleaksignore")); err != nil {
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore") t.Fatalf("could not call AddGitleaksIgnore: %v", err)
} }
findings, err := detector.DetectGit(tt.source, tt.logOpts, ProtectStagedType) findings, err := detector.DetectGit(tt.source, tt.logOpts, ProtectStagedType)
if err != nil { if err != nil {
@@ -663,7 +662,7 @@ func TestFromFiles(t *testing.T) {
var ignorePath string var ignorePath string
info, err := os.Stat(tt.source) info, err := os.Stat(tt.source)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore") t.Fatalf("could not call os.Stat: %v", err)
} }
if info.IsDir() { if info.IsDir() {
@@ -672,7 +671,7 @@ func TestFromFiles(t *testing.T) {
ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore") ignorePath = filepath.Join(filepath.Dir(tt.source), ".gitleaksignore")
} }
if err = detector.AddGitleaksIgnore(ignorePath); err != nil { if err = detector.AddGitleaksIgnore(ignorePath); err != nil {
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore") t.Fatalf("could not call AddGitleaksIgnore: %v", err)
} }
detector.FollowSymlinks = true detector.FollowSymlinks = true
findings, err := detector.DetectFiles(tt.source) findings, err := detector.DetectFiles(tt.source)