grpctest

package
v0.6.13 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupRegistry added in v0.6.1

func SetupRegistry(ctx context.Context, t *testing.T, projectID string, seeds []seeder.RegistryResource) (*gapic.RegistryClient, *gapic.AdminClient)

SetupRegistry connects to a registry instance using the default config, deletes the project if it exists, seeds the registry for testing, and returns the connections used. It also registers cleanup handlers on the test to close the connections and delete the project.

func TestMain

func TestMain(m *testing.M, rc registry.Config)

TestMain can delegate here in packages that wish to use TestMain() for tests relying on a RegistryServer. Note: As TestMain() is run once per TestXXX() function, this will create a new database for the function, not per t.Run() within it. See NewIfNoAddress() for details. Example:

func TestMain(m *testing.M) {
	grpctest.TestMain(m, registry.Config{})
}

Types

type Server

type Server struct {
	Server   *grpc.Server
	Listener net.Listener
	Registry *registry.RegistryServer
	TmpDir   string
}

Server wraps a gRPC Server for a RegistryServer

func NewIfNoAddress

func NewIfNoAddress(rc registry.Config) (*Server, error)

NewIfNoAddress will create a RegistryServer served by a basic grpc.Server if env var REGISTRY_ADDRESS is not set, see NewServer() for details. If REGISTRY_ADDRESS is set, returns nil as client will connect to that remote address. Example:

func TestXXX(t *testing.T) {
	 l, err := grpctest.NewIfNoAddress(registry.Config{})
	 if err != nil {
		t.Fatal(err)
	 }
	 defer l.Close()
  ... run test here ...
}

func NewServer

func NewServer(rc registry.Config) (*Server, error)

NewServer creates a RegistryServer served by a basic grpc.Server. If rc.Database and rc.DBConfig are blank, a RegistryServer using sqlite3 on a tmpDir is automatically created. registry.address and registry.insecure configuration values are set to cause the in-process client to connect to the created grpc service. Call Close() when done to close server and clean up tmpDir as needed. Example:

func TestXXX(t *testing.T) {
	 l, err := grpctest.NewServer(registry.Config{})
	 if err != nil {
		t.Fatal(err)
	 }
	 defer l.Close()
  ... run test here ...
}

func (*Server) Address

func (s *Server) Address() string

Address returns the address of the listener

func (*Server) Close

func (s *Server) Close()

Close will gracefully stop the server and remove tmpDir

func (*Server) Port

func (s *Server) Port() int

Port returns the port of the listener

Jump to

Keyboard shortcuts

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