forked from alexellis/derek
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermissionsHandler_test.go
More file actions
181 lines (166 loc) · 4.62 KB
/
permissionsHandler_test.go
File metadata and controls
181 lines (166 loc) · 4.62 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package main
import (
"testing"
"github.com/alexellis/derek/types"
)
func Test_maintainersparsed(t *testing.T) {
config := types.DerekConfig{}
parseConfig([]byte(`maintainers:
- alexellis
- rgee0
`), &config)
actual := len(config.Maintainers)
if actual != 2 {
t.Errorf("want: %d maintainers, got: %d", 2, actual)
}
}
func Test_curatorequalsmaintainer(t *testing.T) {
config := types.DerekConfig{}
parseConfig([]byte(`curators:
- alexellis
- rgee0
`), &config)
actual := len(config.Maintainers)
if actual != 2 {
t.Errorf("want: %d maintainers, got: %d", 2, actual)
}
}
func Test_enabledFeature(t *testing.T) {
var enableFeatureOpts = []struct {
title string
attemptedFeature string
configFeatures []string
expectedVal bool
}{
{
title: "dco enabled try dco case sensitive",
attemptedFeature: "dco_check",
configFeatures: []string{"dco_check"},
expectedVal: true,
},
{
title: "dco enabled try dco case insensitive",
attemptedFeature: "DCO_check",
configFeatures: []string{"dco_check"},
expectedVal: true,
},
{
title: "dco enabled try comments",
attemptedFeature: "comments",
configFeatures: []string{"dco_check"},
expectedVal: false,
},
{
title: "Comments enabled try comments case insensitive",
attemptedFeature: "Comments",
configFeatures: []string{"comments"},
expectedVal: true,
},
{
title: "Comments enabled try comments case sensitive",
attemptedFeature: "comments",
configFeatures: []string{"comments"},
expectedVal: true,
},
{
title: "Comments enabled try dco",
attemptedFeature: "dco",
configFeatures: []string{"comments"},
expectedVal: false,
},
{
title: "Non-existent feature",
attemptedFeature: "gibberish",
configFeatures: []string{"dco_check", "comments"},
expectedVal: false,
},
}
for _, test := range enableFeatureOpts {
t.Run(test.title, func(t *testing.T) {
inputConfig := &types.DerekConfig{Features: test.configFeatures}
featureEnabled := enabledFeature(test.attemptedFeature, inputConfig)
if featureEnabled != test.expectedVal {
t.Errorf("Enabled feature - wanted: %t, found %t", test.expectedVal, featureEnabled)
}
})
}
}
func Test_permittedUserFeature(t *testing.T) {
var permittedUserFeatureOpts = []struct {
title string
attemptedFeature string
user string
config types.DerekConfig
expectedVal bool
}{
{
title: "Valid feature with valid maintainer",
attemptedFeature: "comment",
user: "Burt",
config: types.DerekConfig{
Features: []string{"comment"},
Maintainers: []string{"Burt", "Tarquin", "Blanche"},
},
expectedVal: true,
},
{
title: "Valid feature with valid maintainer case insensitive",
attemptedFeature: "comment",
user: "burt",
config: types.DerekConfig{
Features: []string{"comment"},
Maintainers: []string{"Burt", "Tarquin", "Blanche"},
},
expectedVal: true,
},
{
title: "Valid feature with invalid maintainer",
attemptedFeature: "comment",
user: "ernie",
config: types.DerekConfig{
Features: []string{"comment"},
Maintainers: []string{"Burt", "Tarquin", "Blanche"},
},
expectedVal: false,
},
{
title: "Valid feature with invalid maintainer case insensitive",
attemptedFeature: "Comment",
user: "ernie",
config: types.DerekConfig{
Features: []string{"comment"},
Maintainers: []string{"Burt", "Tarquin", "Blanche"},
},
expectedVal: false,
},
{
title: "Invalid feature with valid maintainer",
attemptedFeature: "invalid",
user: "Burt",
config: types.DerekConfig{
Features: []string{"comment"},
Maintainers: []string{"Burt", "Tarquin", "Blanche"},
},
expectedVal: false,
},
{
title: "Invalid feature with valid maintainer case insensitive",
attemptedFeature: "invalid",
user: "burt",
config: types.DerekConfig{
Features: []string{"comment"},
Maintainers: []string{"Burt", "Tarquin", "Blanche"},
},
expectedVal: false,
},
}
for _, test := range permittedUserFeatureOpts {
t.Run(test.title, func(t *testing.T) {
inputConfig := &test.config
permittedFeature := permittedUserFeature(test.attemptedFeature, inputConfig, test.user)
if permittedFeature != test.expectedVal {
t.Errorf("Permitted user feature - wanted: %t, found %t", test.expectedVal, permittedFeature)
}
})
}
}