forked from brittonhayes/pillager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmarks_test.go
56 lines (50 loc) · 1.11 KB
/
benchmarks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main_test
import (
"log"
"os"
"testing"
"github.com/brittonhayes/pillager/hunter"
"github.com/brittonhayes/pillager/rules"
"github.com/spf13/afero"
"github.com/zricethezav/gitleaks/v7/scan"
)
// A benchmark of the Hunter Load Rules method
func BenchmarkHunterLoadRules(b *testing.B) {
for n := 0; n < b.N; n++ {
rules.Load("")
}
}
// A benchmark of the Hound Howl method which
// prints results out in desired format
func BenchmarkHunterHoundHowl(b *testing.B) {
b.StopTimer()
h := hunter.NewHound(&hunter.Config{
System: afero.NewMemMapFs(),
Gitleaks: rules.Load(""),
Format: hunter.JSONFormat,
})
findings := scan.Report{
Leaks: []scan.Leak{
{Line: "[email protected]", LineNumber: 16, Offender: "[email protected]", Rule: "Email Addresses"},
},
}
b.StartTimer()
for n := 0; n < b.N; n++ {
defer quiet()()
h.Howl(findings)
}
}
func quiet() func() {
null, _ := os.Open(os.DevNull)
sout := os.Stdout
serr := os.Stderr
os.Stdout = null
os.Stderr = null
log.SetOutput(null)
return func() {
defer null.Close()
os.Stdout = sout
os.Stderr = serr
log.SetOutput(os.Stderr)
}
}