* fixing some v7 bugs
This commit is contained in:
Zachary Rice authored and GitHub committed 2020-12-05 11:57:43 -05:00
1 parent af26553292
commit 7db08bfd90
22 files changed
+783 -550

No files matched your search

+21 -8
View File
@@ -10,8 +10,6 @@ import (
"sort"
"testing"
"github.com/zricethezav/gitleaks/v7/report"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
@@ -419,6 +417,17 @@ func TestScan(t *testing.T) {
},
wantPath: "../test_data/test_file1_aws_leak.json",
},
{
description: "test only md files no git",
opts: options.Options{
Path: "../test_data/test_repos/",
Report: "../test_data/test_only_files_no_git.json.got",
ReportFormat: "json",
ConfigPath: "../test_data/test_configs/onlyFiles.toml",
NoGit: true,
},
wantPath: "../test_data/test_only_files_no_git.json",
},
}
for _, test := range tests {
@@ -457,7 +466,7 @@ func TestScan(t *testing.T) {
t.Fatal(err)
}
err = report.WriteReport(scannerReport, test.opts, cfg)
err = WriteReport(scannerReport, test.opts, cfg)
if err != nil {
t.Error(err)
}
@@ -584,7 +593,7 @@ func TestScanUncommited(t *testing.T) {
t.Fatal(err)
}
err = report.WriteReport(scannerReport, test.opts, cfg)
err = WriteReport(scannerReport, test.opts, cfg)
if err != nil {
t.Error(err)
}
@@ -611,8 +620,8 @@ func TestScanUncommited(t *testing.T) {
func fileCheck(wantPath, gotPath string) error {
var (
gotLeaks []report.Leak
wantLeaks []report.Leak
gotLeaks []Leak
wantLeaks []Leak
)
want, err := ioutil.ReadFile(wantPath)
if err != nil {
@@ -634,8 +643,12 @@ func fileCheck(wantPath, gotPath string) error {
return err
}
sort.Slice(gotLeaks, func(i, j int) bool { return (gotLeaks)[i].Commit < (gotLeaks)[j].Commit })
sort.Slice(wantLeaks, func(i, j int) bool { return (wantLeaks)[i].Commit < (wantLeaks)[j].Commit })
sort.Slice(gotLeaks, func(i, j int) bool {
return (gotLeaks)[i].Offender+(gotLeaks)[i].File < (gotLeaks)[j].Offender+(gotLeaks)[j].File
})
sort.Slice(wantLeaks, func(i, j int) bool {
return (wantLeaks)[i].Offender+(wantLeaks)[i].File < (wantLeaks)[j].Offender+(wantLeaks)[j].File
})
if !reflect.DeepEqual(gotLeaks, wantLeaks) {
dmp := diffmatchpatch.New()