...

Source file src/github.com/emicklei/proto/walk_test.go

Documentation: github.com/emicklei/proto

     1  package proto
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  type counter struct {
     9  	counts map[string]int
    10  }
    11  
    12  func (c counter) handleService(s *Service) {
    13  	c.counts["service"] = c.counts["service"] + 1
    14  }
    15  
    16  func (c counter) handleRPC(r *RPC) {
    17  	c.counts["rpc"] = c.counts["rpc"] + 1
    18  }
    19  
    20  func (c counter) handleImport(r *Import) {
    21  	c.counts["import"] = c.counts["import"] + 1
    22  }
    23  
    24  func (c counter) handleNormalField(r *NormalField) {
    25  	c.counts["normal field"] = c.counts["import"] + 1
    26  }
    27  
    28  func TestWalkGoogleApisDLP(t *testing.T) {
    29  	if len(os.Getenv("PB")) == 0 {
    30  		t.Skip("PB test not run")
    31  	}
    32  	proto := fetchAndParse(t, "https://raw.githubusercontent.com/gogo/protobuf/master/test/theproto3/theproto3.proto")
    33  	count := counter{counts: map[string]int{}}
    34  	Walk(proto,
    35  		WithPackage(func(p *Package) {
    36  			t.Log("package:", p.Name)
    37  		}),
    38  		WithService(count.handleService),
    39  		WithRPC(count.handleRPC),
    40  		WithImport(count.handleImport),
    41  		WithNormalField(count.handleNormalField),
    42  	)
    43  	t.Logf("%#v", count)
    44  }
    45  

View as plain text