@@ -7,6 +7,8 @@ package gps
7
7
import (
8
8
"reflect"
9
9
"testing"
10
+
11
+ "github.com/golang/dep/internal/gps/pkgtree"
10
12
)
11
13
12
14
func TestRootdataExternalImports (t * testing.T ) {
@@ -222,3 +224,58 @@ func TestGetApplicableConstraints(t *testing.T) {
222
224
})
223
225
}
224
226
}
227
+
228
+ func TestIsIgnored (t * testing.T ) {
229
+ cases := []struct {
230
+ name string
231
+ ignorePkgs map [string ]bool
232
+ wantIgnored []string
233
+ wantNotIgnored []string
234
+ }{
235
+ {
236
+ name : "no ignore" ,
237
+ },
238
+ {
239
+ name : "ignores without wildcard" ,
240
+ ignorePkgs : map [string ]bool {
241
+ "a/b/c" : true ,
242
+ "m/n" : true ,
243
+ "gophers" : true ,
244
+ },
245
+ wantIgnored : []string {"a/b/c" , "m/n" , "gophers" },
246
+ wantNotIgnored : []string {"somerandomstring" },
247
+ },
248
+ {
249
+ name : "ignores with wildcard" ,
250
+ ignorePkgs : map [string ]bool {
251
+ "a/b/c*" : true ,
252
+ "m/n*/o" : true ,
253
+ "*x/y/z" : true ,
254
+ "A/B*/C/D*" : true ,
255
+ },
256
+ wantIgnored : []string {"a/b/c" , "a/b/c/d" , "a/b/c-d" , "m/n*/o" , "*x/y/z" , "A/B*/C/D" , "A/B*/C/D/E" },
257
+ wantNotIgnored : []string {"m/n/o" , "m/n*" , "x/y/z" , "*x/y/z/a" , "*x" , "A/B" , "A/B*/C" },
258
+ },
259
+ }
260
+
261
+ for _ , c := range cases {
262
+ t .Run (c .name , func (t * testing.T ) {
263
+ rd := rootdata {
264
+ ig : c .ignorePkgs ,
265
+ igpfx : pkgtree .CreateIgnorePrefixTree (c .ignorePkgs ),
266
+ }
267
+
268
+ for _ , p := range c .wantIgnored {
269
+ if ! rd .isIgnored (p ) {
270
+ t .Fatalf ("expected %q to be ignored" , p )
271
+ }
272
+ }
273
+
274
+ for _ , p := range c .wantNotIgnored {
275
+ if rd .isIgnored (p ) {
276
+ t .Fatalf ("expected %q to be not ignored" , p )
277
+ }
278
+ }
279
+ })
280
+ }
281
+ }
0 commit comments