Documentation ¶
Index ¶
- func AssertAllProtoMethodsAnnotated(t *testing.T, file string, vsnIdentifier string)
- func AssertCode(t *testing.T, expected codes.Code, err error) bool
- func AssertCompiledInUpToDate(t *testing.T, dirs ...string)
- func AssertGeneratedPolicyUpToDate(t *testing.T, file string)
- func AssertReflection(t *testing.T, serv *grpc.Server)
- func ConvertToFDPs(fds []*desc.FileDescriptor) []*descriptor.FileDescriptorProto
- func FindServiceProtos(t *testing.T, dirs ...string) []string
- func GenerateCode(t *testing.T, pluginName string, fds []*desc.FileDescriptor) (*plugin.CodeGeneratorResponse, func(), error)
- func ParseProtoFiles(files []string) ([]*desc.FileDescriptor, error)
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertAllProtoMethodsAnnotated ¶
AssertAllProtoMethodsAnnotated checks, for each policy version, that each public method on each service in each proto file is instrumented with a resource and an action.
func AssertCode ¶
AssertCode is an assertion helper that unwraps the passed error argument, and compares its code to the expected code argument. On mismatch, it displays the textual code representation. Fails the test if the passed error is nil. Returns true if the assertion was met (same as the well-known testify methods).
func AssertCompiledInUpToDate ¶
AssertCompiledInUpToDate is an assertion that, given a set of directories containing .proto files, such as components/teams-service/teams/, asserts that the protobuf descriptor content that is compiled in is in sync with the content of the file on disk. To do so, it uses the protoreflect library to parse data from both sources, and string-compares the pretty-printed proto3 source of both. Note that this way, whitespace- or comment-only changes do not matter.
func AssertGeneratedPolicyUpToDate ¶
AssertGeneratedPolicyUpToDate checks that the generated `*.pb.policy.go` files corresponding to the proto files with policy-related annotations are up to date, i.e., haven't been forgotten to be included in a commit. Its argument is a `*.proto` file with policy annotations on its service's methods.
func AssertReflection ¶
AssertReflection checks if the passed *grpc.Server instance supports reflection. It thereby checks that all the used proto files (e.g. for adding validation rules, or policy info) can be retrieved through this service. This is a requirement for being able to use fullstackdev/grpcurl with the exposed service.
func ConvertToFDPs ¶
func ConvertToFDPs(fds []*desc.FileDescriptor) []*descriptor.FileDescriptorProto
ConvertToFDPs takes a slice of *desc.FileDescriptor (as returned by either protoparse.ParseFiles, or desc.LoadFileDescriptor), and returns the (reverse) topologically sorted slice of *descriptor.FileDescriptorProto that contains all the dependencies in the right order (i.e., before they're imported), and can be used to create a plugin.CodeGeneratorRequest.
func FindServiceProtos ¶
FindServiceProtos walks the passed directories, and returns the filenames of those `.proto` files that contain service definitions. It's meant to be used in conjunction with grpctest.AssertGeneratedPolicyUpToDate, to not have to enumerate all relevant `.proto` files in tests.
func GenerateCode ¶
func GenerateCode(t *testing.T, pluginName string, fds []*desc.FileDescriptor) (*plugin.CodeGeneratorResponse, func(), error)
GenerateCode runs a PGS-based code generator (in memory), and returns its response (*plugin.CodeGeneratorResponse)
func ParseProtoFiles ¶
func ParseProtoFiles(files []string) ([]*desc.FileDescriptor, error)
ParseProtoFiles takes a slice of string filenames, like
"api/interservice/authz/authz.proto"
attempts to parse them, and returns a slice of *desc.FileDescriptor on success.
Types ¶
type Server ¶
type Server struct { URL string // base URL of form ipaddr:port with no trailing slash Listener net.Listener // Config may be changed after calling NewUnstartedServer and // before Start. Config *grpc.Server }
A Server is an HTTP server listening on a system-chosen port on the local loopback interface, for use in end-to-end HTTP tests.
func NewServer ¶
NewServer starts and returns a new Server. The caller should call Close when finished, to shut it down.
func NewUnstartedServer ¶
NewUnstartedServer returns a new Server but doesn't start it.
After changing its configuration, the caller should call Start.
The caller should call Close when finished, to shut it down.