Documentation
¶
Overview ¶
Package testutil provides testing utilities for gRPC integration tests
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFreeAddress ¶
GetFreeAddress returns a free address in the format "localhost:port"
func GetFreePort ¶
GetFreePort asks the kernel for a free open port that is ready to use. This is a common pattern in integration tests to avoid port conflicts.
Types ¶
type ClientOptions ¶
type ClientOptions struct {
// EnableTLS enables mTLS authentication (must match server)
EnableTLS bool
// CertFile path to client certificate (required if EnableTLS is true)
CertFile string
// KeyFile path to client key (required if EnableTLS is true)
KeyFile string
// CAFile path to CA certificate (required if EnableTLS is true)
CAFile string
// Timeout for connection (default: 5 seconds)
Timeout time.Duration
}
ClientOptions configures the test client
func DefaultClientOptions ¶
func DefaultClientOptions() ClientOptions
DefaultClientOptions returns default client options with TLS enabled
type ServerOptions ¶
type ServerOptions struct {
// EnableTLS enables mTLS authentication (default: true)
EnableTLS bool
// MockOcservSocket path to mock ocserv socket (optional)
MockOcservSocket string
// AgentID for the server (default: "test-agent")
AgentID string
// Address to listen on (default: auto-allocated)
Address string
}
ServerOptions configures the test server
func DefaultServerOptions ¶
func DefaultServerOptions() ServerOptions
DefaultServerOptions returns default server options with TLS enabled
type TestClient ¶
type TestClient struct {
Conn *grpc.ClientConn
Client pb.AgentServiceClient
// contains filtered or unexported fields
}
TestClient wraps a gRPC client for testing
func NewTestClient ¶
func NewTestClient(t *testing.T, address string, opts ClientOptions) *TestClient
NewTestClient creates a new gRPC test client
type TestServer ¶
type TestServer struct {
Server *grpcserver.Server
Address string
Config *config.Config
CertDir string
// contains filtered or unexported fields
}
TestServer represents a gRPC server instance for testing
func NewTestServer ¶
func NewTestServer(t *testing.T, opts ServerOptions) *TestServer
NewTestServer creates and starts a new gRPC test server
func (*TestServer) GetCertFiles ¶
func (ts *TestServer) GetCertFiles() (certFile, keyFile, caFile string)
GetCertFiles returns paths to the certificate files (for client creation)
func (*TestServer) Shutdown ¶
func (ts *TestServer) Shutdown()
Shutdown gracefully stops the test server