gopkg.in/alecthomas/gometalinter.v3@v3.0.0/_linters/src/github.com/securego/gosec/testutils/visitor.go (about) 1 package testutils 2 3 import ( 4 "go/ast" 5 6 "github.com/securego/gosec" 7 ) 8 9 // MockVisitor is useful for stubbing out ast.Visitor with callback 10 // and looking for specific conditions to exist. 11 type MockVisitor struct { 12 Context *gosec.Context 13 Callback func(n ast.Node, ctx *gosec.Context) bool 14 } 15 16 // NewMockVisitor creates a new empty struct, the Context and 17 // Callback must be set manually. See call_list_test.go for an example. 18 func NewMockVisitor() *MockVisitor { 19 return &MockVisitor{} 20 } 21 22 // Visit satisfies the ast.Visitor interface 23 func (v *MockVisitor) Visit(n ast.Node) ast.Visitor { 24 if v.Callback(n, v.Context) { 25 return v 26 } 27 return nil 28 }