forked from gitleaks/gitleaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
88 lines (80 loc) · 1.4 KB
/
options_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"testing"
)
func TestNextInt(t *testing.T) {
args := []string{"-c", "10"}
i := 0
opts, err := defaultOptions()
if err != nil {
t.Error()
}
n := opts.nextInt(args, &i)
if n != 10 {
t.Error()
}
}
func TestNextString(t *testing.T) {
args := []string{"--fake", "flag"}
i := 0
opts, err := defaultOptions()
if err != nil {
t.Error()
}
n := opts.nextString(args, &i)
if n != "flag" {
t.Error()
}
}
func TestOptString(t *testing.T) {
opts, err := defaultOptions()
if err != nil {
t.Error()
}
match, n := opts.optString("--fake=flag", "--fake=")
if !match || n != "flag" {
t.Error()
}
}
func TestOptInt(t *testing.T) {
opts, err := defaultOptions()
if err != nil {
t.Error()
}
match, n := opts.optInt("--fake=10", "--fake=")
if !match || n != 10 {
t.Error()
}
}
func TestParseOptions(t *testing.T) {
opts, err := defaultOptions()
opts.URL = "github.com/sample"
if err != nil {
t.Error()
}
opts.RepoMode = false
opts.UserMode = true
opts.LocalMode = true
err = opts.guards()
if err == nil {
t.Error()
}
opts.RepoMode = true
opts.UserMode = false
opts.LocalMode = false
err = opts.guards()
if err != nil {
t.Error()
}
}
func TestGithubTarget(t *testing.T) {
if !isGithubTarget("github.com") {
t.Error()
}
if !isGithubTarget("https://github.com/") {
t.Error()
}
if !isGithubTarget("[email protected]:zricethezav/gitleaks.git") {
t.Error()
}
}