-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathallowed_test.go
70 lines (64 loc) · 1.64 KB
/
allowed_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
package gomodguard_test
import (
"reflect"
"testing"
"github.com/ryancurrah/gomodguard"
)
func TestAllowedIsAllowedModule(t *testing.T) {
var tests = []struct {
testName string
allowedModules gomodguard.Allowed
lintedModuleName string
wantIsAllowedModule bool
}{
{
"module is allowed",
gomodguard.Allowed{Modules: []string{"github.com/someallowed/module"}},
"github.com/someallowed/module",
true,
},
{
"module not allowed",
gomodguard.Allowed{},
"github.com/someblocked/module",
false,
},
}
for _, tt := range tests {
t.Run(tt.testName, func(t *testing.T) {
isAllowedModule := tt.allowedModules.IsAllowedModule(tt.lintedModuleName)
if !reflect.DeepEqual(isAllowedModule, tt.wantIsAllowedModule) {
t.Errorf("got '%v' want '%v'", isAllowedModule, tt.wantIsAllowedModule)
}
})
}
}
func TestAllowedIsAllowedModuleDomain(t *testing.T) {
var tests = []struct {
testName string
allowedModules gomodguard.Allowed
lintedModuleName string
wantIsAllowedModuleDomain bool
}{
{
"module is allowed",
gomodguard.Allowed{Domains: []string{"github.com"}},
"github.com/someallowed/module",
true,
},
{
"module not allowed",
gomodguard.Allowed{},
"github.com/someblocked/module",
false,
},
}
for _, tt := range tests {
t.Run(tt.testName, func(t *testing.T) {
isAllowedModuleDomain := tt.allowedModules.IsAllowedModuleDomain(tt.lintedModuleName)
if !reflect.DeepEqual(isAllowedModuleDomain, tt.wantIsAllowedModuleDomain) {
t.Errorf("got '%v' want '%v'", isAllowedModuleDomain, tt.wantIsAllowedModuleDomain)
}
})
}
}