grpctest

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 APG_REGISTRY_ADDRESS is not set, see NewServer() for details. If APG_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. APG_REGISTRY_ADDRESS and APG_REGISTRY_INSECURE env vars are set for the 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