mirror of
https://github.com/securego/gosec.git
synced 2024-12-29 05:55:51 +00:00
6943f9e5e4
- Get rid of 'core' and move CLI to cmd/gas directory - Migrate (most) tests to use Ginkgo and testutils framework - GAS now expects package to reside in $GOPATH - GAS now can resolve dependencies for better type checking (if package on GOPATH) - Simplified public API
28 lines
647 B
Go
28 lines
647 B
Go
package testutils
|
|
|
|
import (
|
|
"go/ast"
|
|
|
|
"github.com/GoASTScanner/gas"
|
|
)
|
|
|
|
// MockVisitor is useful for stubbing out ast.Visitor with callback
|
|
// and looking for specific conditions to exist.
|
|
type MockVisitor struct {
|
|
Context *gas.Context
|
|
Callback func(n ast.Node, ctx *gas.Context) bool
|
|
}
|
|
|
|
// NewMockVisitor creates a new empty struct, the Context and
|
|
// Callback must be set manually. See call_list_test.go for an example.
|
|
func NewMockVisitor() *MockVisitor {
|
|
return &MockVisitor{}
|
|
}
|
|
|
|
// Visit satisfies the ast.Visitor interface
|
|
func (v *MockVisitor) Visit(n ast.Node) ast.Visitor {
|
|
if v.Callback(n, v.Context) {
|
|
return v
|
|
}
|
|
return nil
|
|
}
|