forked from gitleaks/gitleaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo_test.go
65 lines (59 loc) · 1.23 KB
/
repo_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
57
58
59
60
61
62
63
64
65
package main
import (
"os"
"testing"
)
func TestNewLocalRepo(t *testing.T) {
r := newLocalRepo("")
if r.path != "" {
t.Error()
}
r = newLocalRepo("some/path")
if r.name != "path" || r.path != "some/path" {
t.Error()
}
}
func TestWriteReport(t *testing.T) {
opts, _ = defaultOptions()
r := newRepo("fakerepo", "github.com", "")
r.leaks = []Leak{*sampleLeak(), *sampleLeak()}
r.writeReport(r.leaks)
if _, err := os.Stat("fakerepo_leaks.json"); os.IsNotExist(err) {
t.Error()
} else {
os.Remove("fakerepo_leaks.json")
}
}
func TestAudit(t *testing.T) {
opts, _ = defaultOptions()
opts.RepoMode = true
opts.Tmp = true
opts.URL = "https://github.com/zricethezav/gronit"
owner := newOwner()
r := newRepo("gronit", opts.URL, owner.path)
leaksPst, _ := r.audit()
if !leaksPst {
// TODO setup actual test repo
t.Error()
}
// new owner
opts.URL = "https://github.com/kelseyhightower/nocode"
owner = newOwner()
r = newRepo("nocode", opts.URL, owner.path)
leaksPst, _ = r.audit()
if leaksPst {
t.Error()
}
}
func sampleLeak() *Leak {
return &Leak{
Line: "yoo",
Commit: "mycommit",
Offender: "oh boy",
Reason: "hello",
Msg: "msg",
Time: "time",
Author: "lol",
RepoURL: "yooo",
}
}