-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
walk_test.go
44 lines (37 loc) · 980 Bytes
/
walk_test.go
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
package proto
import (
"os"
"testing"
)
type counter struct {
counts map[string]int
}
func (c counter) handleService(s *Service) {
c.counts["service"] = c.counts["service"] + 1
}
func (c counter) handleRPC(r *RPC) {
c.counts["rpc"] = c.counts["rpc"] + 1
}
func (c counter) handleImport(r *Import) {
c.counts["import"] = c.counts["import"] + 1
}
func (c counter) handleNormalField(r *NormalField) {
c.counts["normal field"] = c.counts["import"] + 1
}
func TestWalkGoogleApisDLP(t *testing.T) {
if len(os.Getenv("PB")) == 0 {
t.Skip("PB test not run")
}
proto := fetchAndParse(t, "https://raw.githubusercontent.com/gogo/protobuf/master/test/theproto3/theproto3.proto")
count := counter{counts: map[string]int{}}
Walk(proto,
WithPackage(func(p *Package) {
t.Log("package:", p.Name)
}),
WithService(count.handleService),
WithRPC(count.handleRPC),
WithImport(count.handleImport),
WithNormalField(count.handleNormalField),
)
t.Logf("%#v", count)
}