-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_concurrent_test.go
More file actions
62 lines (50 loc) · 1.04 KB
/
Copy pathfilter_concurrent_test.go
File metadata and controls
62 lines (50 loc) · 1.04 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
package gogenfilter
import (
"sync"
"testing"
"testing/fstest"
)
func TestFilterConcurrent(t *testing.T) {
t.Parallel()
mapFS := fstest.MapFS{
dbModelsGo: newMapFile(sqlcGeneratedContentTest),
mainGo: newMapFile(packageMainFunc),
apiGo: newMapFile("package main\n"),
}
opts, err := WithFilterOptions(FilterAll)
if err != nil {
t.Fatal(err)
}
filter, err := NewFilter(
opts,
WithFS(mapFS),
)
if err != nil {
t.Fatal(err)
}
const goroutines = 100
var waitGroup sync.WaitGroup
waitGroup.Add(goroutines)
for i := range goroutines {
go func() {
defer waitGroup.Done()
files := []string{dbModelsGo, mainGo, apiGo}
file := files[i%len(files)]
filtered, err := filter.Filter(file)
if err != nil {
t.Errorf("Filter(%q) error: %v", file, err)
}
switch file {
case dbModelsGo:
if !filtered {
t.Error("expected db/models.go to be filtered")
}
case mainGo, apiGo:
if filtered {
t.Errorf("expected %s to not be filtered", file)
}
}
}()
}
waitGroup.Wait()
}