@@ -47,13 +47,21 @@ func TestBlockedModuleIsAllowed(t *testing.T) {
47
47
}{
48
48
{
49
49
"blocked" ,
50
- gomodguard.BlockedModule {Recommendations : []string {"github.com/somerecommended/module" }},
50
+ gomodguard.BlockedModule {
51
+ Recommendations : []string {
52
+ "github.com/somerecommended/module" ,
53
+ },
54
+ },
51
55
"github.com/ryancurrah/gomodguard" ,
52
56
false ,
53
57
},
54
58
{
55
59
"allowed" ,
56
- gomodguard.BlockedModule {Recommendations : []string {"github.com/ryancurrah/gomodguard" }},
60
+ gomodguard.BlockedModule {
61
+ Recommendations : []string {
62
+ "github.com/ryancurrah/gomodguard" ,
63
+ },
64
+ },
57
65
"github.com/ryancurrah/gomodguard" ,
58
66
true ,
59
67
},
@@ -72,7 +80,8 @@ func TestBlockedModuleIsAllowed(t *testing.T) {
72
80
func TestBlockedModuleMessage (t * testing.T ) {
73
81
blockedWithNoRecommendation := "Some reason."
74
82
blockedWithRecommendation := "`github.com/somerecommended/module` is a recommended module. Some reason."
75
- blockedWithRecommendations := "`github.com/somerecommended/module`, `github.com/someotherrecommended/module` and `github.com/someotherotherrecommended/module` are recommended modules. Some reason."
83
+ blockedWithRecommendations := "`github.com/somerecommended/module`, `github.com/someotherrecommended/module` " +
84
+ "and `github.com/someotherotherrecommended/module` are recommended modules. Some reason."
76
85
77
86
var tests = []struct {
78
87
testName string
@@ -82,19 +91,34 @@ func TestBlockedModuleMessage(t *testing.T) {
82
91
}{
83
92
{
84
93
"blocked with no recommendation" ,
85
- gomodguard.BlockedModule {Recommendations : []string {}, Reason : "Some reason." },
94
+ gomodguard.BlockedModule {
95
+ Recommendations : []string {},
96
+ Reason : "Some reason." ,
97
+ },
86
98
"github.com/ryancurrah/gomodguard" ,
87
99
blockedWithNoRecommendation ,
88
100
},
89
101
{
90
102
"blocked with recommendation" ,
91
- gomodguard.BlockedModule {Recommendations : []string {"github.com/somerecommended/module" }, Reason : "Some reason." },
103
+ gomodguard.BlockedModule {
104
+ Recommendations : []string {
105
+ "github.com/somerecommended/module" ,
106
+ },
107
+ Reason : "Some reason." ,
108
+ },
92
109
"github.com/ryancurrah/gomodguard" ,
93
110
blockedWithRecommendation ,
94
111
},
95
112
{
96
113
"blocked with multiple recommendations" ,
97
- gomodguard.BlockedModule {Recommendations : []string {"github.com/somerecommended/module" , "github.com/someotherrecommended/module" , "github.com/someotherotherrecommended/module" }, Reason : "Some reason." },
114
+ gomodguard.BlockedModule {
115
+ Recommendations : []string {
116
+ "github.com/somerecommended/module" ,
117
+ "github.com/someotherrecommended/module" ,
118
+ "github.com/someotherotherrecommended/module" ,
119
+ },
120
+ Reason : "Some reason." ,
121
+ },
98
122
"github.com/ryancurrah/gomodguard" ,
99
123
blockedWithRecommendations ,
100
124
},
@@ -123,7 +147,11 @@ func TestBlockedModuleHasRecommendations(t *testing.T) {
123
147
},
124
148
{
125
149
"does have recommendations" ,
126
- gomodguard.BlockedModule {Recommendations : []string {"github.com/ryancurrah/gomodguard" }},
150
+ gomodguard.BlockedModule {
151
+ Recommendations : []string {
152
+ "github.com/ryancurrah/gomodguard" ,
153
+ },
154
+ },
127
155
true ,
128
156
},
129
157
}
@@ -146,7 +174,15 @@ func TestBlockedModulesGet(t *testing.T) {
146
174
}{
147
175
{
148
176
"get all blocked module names" ,
149
- gomodguard.BlockedModules {{"github.com/someblocked/module" : gomodguard.BlockedModule {Recommendations : []string {"github.com/ryancurrah/gomodguard" }}}},
177
+ gomodguard.BlockedModules {
178
+ {
179
+ "github.com/someblocked/module" : gomodguard.BlockedModule {
180
+ Recommendations : []string {
181
+ "github.com/ryancurrah/gomodguard" ,
182
+ },
183
+ },
184
+ },
185
+ },
150
186
[]string {"github.com/someblocked/module" },
151
187
},
152
188
}
@@ -162,8 +198,10 @@ func TestBlockedModulesGet(t *testing.T) {
162
198
}
163
199
164
200
func TestBlockedVersionMessage (t * testing.T ) {
165
- blockedWithVersionConstraint := "version `1.0.0` is blocked because it does not meet the version constraint `1.0.0`. Some reason."
166
- blockedWithVersionConstraintNoReason := "version `1.0.0` is blocked because it does not meet the version constraint `<= 1.0.0`."
201
+ blockedWithVersionConstraint := "version `1.0.0` is blocked because it does not meet the version constraint " +
202
+ "`1.0.0`. Some reason."
203
+ blockedWithVersionConstraintNoReason := "version `1.0.0` is blocked because it does not meet the version " +
204
+ "constraint `<= 1.0.0`."
167
205
168
206
var tests = []struct {
169
207
testName string
@@ -173,7 +211,10 @@ func TestBlockedVersionMessage(t *testing.T) {
173
211
}{
174
212
{
175
213
"blocked with version constraint" ,
176
- gomodguard.BlockedVersion {Version : "1.0.0" , Reason : "Some reason." },
214
+ gomodguard.BlockedVersion {
215
+ Version : "1.0.0" ,
216
+ Reason : "Some reason." ,
217
+ },
177
218
"1.0.0" ,
178
219
blockedWithVersionConstraint ,
179
220
},
@@ -205,14 +246,30 @@ func TestBlockedModulesGetBlockedModule(t *testing.T) {
205
246
}{
206
247
{
207
248
"blocked" ,
208
- gomodguard.BlockedModules {{"github.com/someblocked/module" : gomodguard.BlockedModule {Recommendations : []string {"github.com/someother/module" }}}},
249
+ gomodguard.BlockedModules {
250
+ {
251
+ "github.com/someblocked/module" : gomodguard.BlockedModule {
252
+ Recommendations : []string {
253
+ "github.com/someother/module" ,
254
+ },
255
+ },
256
+ },
257
+ },
209
258
"github.com/ryancurrah/gomodguard" ,
210
259
"github.com/someblocked/module" ,
211
260
false ,
212
261
},
213
262
{
214
263
"allowed" ,
215
- gomodguard.BlockedModules {{"github.com/someblocked/module" : gomodguard.BlockedModule {Recommendations : []string {"github.com/ryancurrah/gomodguard" }}}},
264
+ gomodguard.BlockedModules {
265
+ {
266
+ "github.com/someblocked/module" : gomodguard.BlockedModule {
267
+ Recommendations : []string {
268
+ "github.com/ryancurrah/gomodguard" ,
269
+ },
270
+ },
271
+ },
272
+ },
216
273
"github.com/ryancurrah/gomodguard" ,
217
274
"github.com/someblocked/module" ,
218
275
true ,
@@ -223,7 +280,8 @@ func TestBlockedModulesGetBlockedModule(t *testing.T) {
223
280
t .Run (tt .testName , func (t * testing.T ) {
224
281
blockedModule := tt .blockedModules .GetBlockReason (tt .lintedModuleName )
225
282
if blockedModule .IsCurrentModuleARecommendation (tt .currentModuleName ) != tt .wantIsAllowed {
226
- t .Errorf ("got '%+v' want '%+v'" , blockedModule .IsCurrentModuleARecommendation (tt .currentModuleName ), tt .wantIsAllowed )
283
+ t .Errorf ("got '%+v' want '%+v'" , blockedModule .IsCurrentModuleARecommendation (tt .currentModuleName ),
284
+ tt .wantIsAllowed )
227
285
}
228
286
})
229
287
}
@@ -337,17 +395,22 @@ func TestProcessorProcessFiles(t *testing.T) {
337
395
{
338
396
"module blocked because of recommendation" ,
339
397
gomodguard.Processor {Config : config , Modfile : processor .Modfile },
340
- "blocked_example.go:9:1 import of package `github.com/uudashr/go-module` is blocked because the module is in the blocked modules list. `golang.org/x/mod` is a recommended module. `mod` is the official go.mod parser library." ,
398
+ "blocked_example.go:9:1 import of package `github.com/uudashr/go-module` is blocked because the " +
399
+ "module is in the blocked modules list. `golang.org/x/mod` is a recommended module. `mod` " +
400
+ "is the official go.mod parser library." ,
341
401
},
342
402
{
343
403
"module blocked because of version constraint" ,
344
404
gomodguard.Processor {Config : config , Modfile : processor .Modfile },
345
- "blocked_example.go:7:1 import of package `github.com/mitchellh/go-homedir` is blocked because the module is in the blocked modules list. version `v1.1.0` is blocked because it does not meet the version constraint `<= 1.1.0`. testing if blocked version constraint works." ,
405
+ "blocked_example.go:7:1 import of package `github.com/mitchellh/go-homedir` is blocked because " +
406
+ "the module is in the blocked modules list. version `v1.1.0` is blocked because it does not " +
407
+ "meet the version constraint `<= 1.1.0`. testing if blocked version constraint works." ,
346
408
},
347
409
{
348
410
"module blocked because of local replace directive" ,
349
411
gomodguard.Processor {Config : config , Modfile : processor .Modfile },
350
- "blocked_example.go:8:1 import of package `github.com/ryancurrah/gomodguard` is blocked because the module has a local replace directive." ,
412
+ "blocked_example.go:8:1 import of package `github.com/ryancurrah/gomodguard` is blocked because " +
413
+ "the module has a local replace directive." ,
351
414
},
352
415
}
353
416
0 commit comments