Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 1e80e66

Browse files
committed
test(gps): add test for rootdata.isIgnored()
1 parent 4021244 commit 1e80e66

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

internal/gps/rootdata_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package gps
77
import (
88
"reflect"
99
"testing"
10+
11+
"github.com/golang/dep/internal/gps/pkgtree"
1012
)
1113

1214
func TestRootdataExternalImports(t *testing.T) {
@@ -222,3 +224,58 @@ func TestGetApplicableConstraints(t *testing.T) {
222224
})
223225
}
224226
}
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

Comments
 (0)