grpctest

package
v0.0.0-...-f54f16c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAllProtoMethodsAnnotated

func AssertAllProtoMethodsAnnotated(t *testing.T, file string, vsnIdentifier string)

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

func AssertCode(t *testing.T, expected codes.Code, err error) bool

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

func AssertCompiledInUpToDate(t *testing.T, dirs ...string)

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

func AssertGeneratedPolicyUpToDate(t *testing.T, file string)

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

func AssertReflection(t *testing.T, serv *grpc.Server)

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

func FindServiceProtos(t *testing.T, dirs ...string) []string

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

func NewServer(s *grpc.Server) *Server

NewServer starts and returns a new Server. The caller should call Close when finished, to shut it down.

func NewUnstartedServer

func NewUnstartedServer(s *grpc.Server) *Server

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.

func (*Server) Close

func (s *Server) Close()

Close shuts down the server immediately, closing all connections and listeners.

func (*Server) Start

func (s *Server) Start()

Start starts a server from NewUnstartedServer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL