Documentation
¶
Index ¶
- Constants
- Variables
- func CheckMetrics(t *testing.T, url string, expectedMetrics ...string)
- func CheckServerStopped(t *testing.T, addr string) bool
- func CreateClientWithTLS[T any](t *testing.T, endpoint *connection.Endpoint, tlsCfg connection.TLSConfig, ...) T
- func CreateDockerNetwork(t *testing.T, name string) *docker.Network
- func CreateServerAndClientTLSConfig(t *testing.T, tlsMode string) (serverTLSConfig, clientTLSConfig connection.TLSConfig)
- func EnsurePersistedTxStatus(ctx context.Context, t *testing.T, r StatusRetriever, txIDs []string, ...)
- func EventuallyIntMetric(t *testing.T, expected int, m prometheus.Metric, waitFor, tick time.Duration, ...)
- func FailHandler(t *testing.T)
- func GetDockerClient(t *testing.T) *docker.Client
- func GetIntMetricValue(t *testing.T, m prometheus.Metric) int
- func GetMetricValue(t *testing.T, m prometheus.Metric) float64
- func GetMetricValueFromURL(t *testing.T, url, metricName string) int
- func LogStruct(t *testing.T, name string, v any)
- func MustCreateEndpoint(value string) *connection.Endpoint
- func NewInsecureClientConfig(ep *connection.Endpoint) *connection.ClientConfig
- func NewInsecureConnection(t *testing.T, endpoint connection.WithAddress) *grpc.ClientConn
- func NewInsecureConnectionWithRetry(t *testing.T, endpoint connection.WithAddress, retry connection.RetryProfile) *grpc.ClientConn
- func NewInsecureLoadBalancedConnection(t *testing.T, endpoints []*connection.Endpoint) *grpc.ClientConn
- func NewSecuredConnection(t *testing.T, endpoint connection.WithAddress, tlsConfig connection.TLSConfig) *grpc.ClientConn
- func NewSecuredConnectionWithRetry(t *testing.T, endpoint connection.WithAddress, tlsConfig connection.TLSConfig, ...) *grpc.ClientConn
- func NewTLSClientConfig(tlsConfig connection.TLSConfig, ep *connection.Endpoint) *connection.ClientConfig
- func NewTLSMultiClientConfig(tlsConfig connection.TLSConfig, ep ...*connection.Endpoint) *connection.MultiClientConfig
- func RemoveDockerNetwork(t *testing.T, name string)
- func RequireIntMetricValue(t *testing.T, expected int, m prometheus.Metric)
- func RequireProtoElementsMatch[T proto.Message](t require.TestingT, expected, actual []T, msgAndArgs ...any)
- func RequireProtoEqual(t require.TestingT, expected, actual proto.Message)
- func RunGrpcServerForTest(ctx context.Context, tb testing.TB, serverConfig *connection.ServerConfig, ...) *grpc.Server
- func RunSecureConnectionTest(t *testing.T, starter ServerStarter)
- func RunServiceAndGrpcForTest(ctx context.Context, t *testing.T, service connection.Service, ...) *channel.Ready
- func RunServiceForTest(ctx context.Context, tb testing.TB, service func(ctx context.Context) error, ...) *channel.Ready
- func ServerToMultiClientConfig(servers ...*connection.ServerConfig) *connection.MultiClientConfig
- func SetupDebugging()
- func WaitUntilGrpcServerIsReady(ctx context.Context, t *testing.T, conn grpc.ClientConnInterface)
- type BroadcastStream
- type Broadcaster
- type CredentialsFactory
- type GrpcServers
- type RPCAttempt
- type ServerStarter
- type StatusRetriever
Constants ¶
const ( //nolint:revive // represents the default certificate's names. PrivateKey = "private-key.pem" PublicKey = "public-key.pem" CACertificateKey = "ca-certificate.pem" )
Variables ¶
var ( // InsecureTLSConfig defines an empty tls config. InsecureTLSConfig connection.TLSConfig )
var ServerModes = []string{connection.MutualTLSMode, connection.OneSideTLSMode, connection.NoneTLSMode}
ServerModes is a list of server-side TLS modes used for testing.
Functions ¶
func CheckMetrics ¶
CheckMetrics checks the metrics endpoint for the expected metrics.
func CheckServerStopped ¶
CheckServerStopped returns true if the grpc server listening on a given address has been stopped.
func CreateClientWithTLS ¶ added in v0.1.7
func CreateClientWithTLS[T any]( t *testing.T, endpoint *connection.Endpoint, tlsCfg connection.TLSConfig, protoClient func(grpc.ClientConnInterface) T, ) T
CreateClientWithTLS creates and returns a typed gRPC client using the provided TLS configuration. It establishes a secure connection to the given endpoint and returns the generated client using the provided client creation proto function.
func CreateDockerNetwork ¶ added in v0.1.7
CreateDockerNetwork creates a network if it doesn't exist.
func CreateServerAndClientTLSConfig ¶ added in v0.1.7
func CreateServerAndClientTLSConfig(t *testing.T, tlsMode string) ( serverTLSConfig, clientTLSConfig connection.TLSConfig, )
CreateServerAndClientTLSConfig creates server and client TLS configurations given a TLS mode.
func EnsurePersistedTxStatus ¶
func EnsurePersistedTxStatus( ctx context.Context, t *testing.T, r StatusRetriever, txIDs []string, expected map[string]*protoblocktx.StatusWithHeight, )
EnsurePersistedTxStatus fails the test if the given TX IDs does not match the expected status.
func EventuallyIntMetric ¶
func EventuallyIntMetric( t *testing.T, expected int, m prometheus.Metric, waitFor, tick time.Duration, msgAndArgs ...any, )
EventuallyIntMetric fail the test if the integer metric is not equal to the expected value after the given duration.
func GetDockerClient ¶ added in v0.1.7
GetDockerClient instantiate a new docker client.
func GetIntMetricValue ¶
func GetIntMetricValue(t *testing.T, m prometheus.Metric) int
GetIntMetricValue returns the value of a prometheus metric, rounded to the nearest integer.
func GetMetricValue ¶
func GetMetricValue(t *testing.T, m prometheus.Metric) float64
GetMetricValue returns the value of a prometheus metric.
func GetMetricValueFromURL ¶
GetMetricValueFromURL reads the metrics endpoint and fetch the value of a specific metric.
func MustCreateEndpoint ¶ added in v0.1.7
func MustCreateEndpoint(value string) *connection.Endpoint
MustCreateEndpoint parses an endpoint from an address string. It panics if it fails to parse.
func NewInsecureClientConfig ¶ added in v0.1.7
func NewInsecureClientConfig(ep *connection.Endpoint) *connection.ClientConfig
NewInsecureClientConfig creates a client configuration for test purposes given an endpoint.
func NewInsecureConnection ¶ added in v0.1.7
func NewInsecureConnection(t *testing.T, endpoint connection.WithAddress) *grpc.ClientConn
NewInsecureConnection creates the default connection with insecure credentials.
func NewInsecureConnectionWithRetry ¶ added in v0.1.7
func NewInsecureConnectionWithRetry( t *testing.T, endpoint connection.WithAddress, retry connection.RetryProfile, ) *grpc.ClientConn
NewInsecureConnectionWithRetry creates the default dial config with insecure credentials.
func NewInsecureLoadBalancedConnection ¶ added in v0.1.7
func NewInsecureLoadBalancedConnection(t *testing.T, endpoints []*connection.Endpoint) *grpc.ClientConn
NewInsecureLoadBalancedConnection creates the default connection with insecure credentials.
func NewSecuredConnection ¶ added in v0.1.7
func NewSecuredConnection( t *testing.T, endpoint connection.WithAddress, tlsConfig connection.TLSConfig, ) *grpc.ClientConn
NewSecuredConnection creates the default connection with given transport credentials.
func NewSecuredConnectionWithRetry ¶ added in v0.1.7
func NewSecuredConnectionWithRetry( t *testing.T, endpoint connection.WithAddress, tlsConfig connection.TLSConfig, retry connection.RetryProfile, ) *grpc.ClientConn
NewSecuredConnectionWithRetry creates the default connection with given transport credentials.
func NewTLSClientConfig ¶ added in v0.1.7
func NewTLSClientConfig(tlsConfig connection.TLSConfig, ep *connection.Endpoint) *connection.ClientConfig
NewTLSClientConfig creates a client configuration for test purposes given a single endpoint and creds.
func NewTLSMultiClientConfig ¶ added in v0.1.7
func NewTLSMultiClientConfig( tlsConfig connection.TLSConfig, ep ...*connection.Endpoint, ) *connection.MultiClientConfig
NewTLSMultiClientConfig creates a multi client configuration for test purposes given number of endpoints and a TLS configuration.
func RemoveDockerNetwork ¶ added in v0.1.7
RemoveDockerNetwork removes a Docker network by name.
func RequireIntMetricValue ¶
func RequireIntMetricValue(t *testing.T, expected int, m prometheus.Metric)
RequireIntMetricValue fail the test if the integer metric is not equal to the expected value.
func RequireProtoElementsMatch ¶
func RequireProtoElementsMatch[T proto.Message]( t require.TestingT, expected, actual []T, msgAndArgs ...any, )
RequireProtoElementsMatch verifies that two arrays of proto have the same elements.
func RequireProtoEqual ¶
RequireProtoEqual verifies that two proto are equal.
func RunGrpcServerForTest ¶
func RunGrpcServerForTest( ctx context.Context, tb testing.TB, serverConfig *connection.ServerConfig, register func(server *grpc.Server), ) *grpc.Server
RunGrpcServerForTest starts a GRPC server using a register method. It handles the cleanup of the GRPC server at the end of a test, and ensure the test is ended only when the GRPC server is down. It also updates the server config endpoint port to the actual port if the configuration did not specify a port. The method asserts that the GRPC server did not end with failure.
func RunSecureConnectionTest ¶ added in v0.1.7
func RunSecureConnectionTest( t *testing.T, starter ServerStarter, )
RunSecureConnectionTest starts a gRPC server with mTLS enabled and tests client connections using various TLS configurations to verify that the server correctly accepts or rejects connections based on the client's setup. It runs a server instance of the service and returns a function that starts a client with the required TLS mode, attempts an RPC call, and returns the resulting error. Server Mode | Client with mTLS | Client with server-side TLS | Client with no TLS ------------|------------------|-----------------------------|-------------------- mTLS | connect | can't connect | can't connect TLS | connect | connect | can't connect None | can't connect | can't connect | connect.
func RunServiceAndGrpcForTest ¶
func RunServiceAndGrpcForTest( ctx context.Context, t *testing.T, service connection.Service, serverConfig ...*connection.ServerConfig, ) *channel.Ready
RunServiceAndGrpcForTest combines running a service and its GRPC server. It is intended for services that implements the Service API (i.e., command line services).
func RunServiceForTest ¶
func RunServiceForTest( ctx context.Context, tb testing.TB, service func(ctx context.Context) error, waitFunc func(ctx context.Context) bool, ) *channel.Ready
RunServiceForTest runs a service using the given service method, and waits for it to be ready given the waitFunc method. It handles the cleanup of the service at the end of a test, and ensure the test is ended only when the service return. The method asserts that the service did not end with failure. Returns a ready flag that indicate that the service is done.
func ServerToMultiClientConfig ¶ added in v0.1.7
func ServerToMultiClientConfig(servers ...*connection.ServerConfig) *connection.MultiClientConfig
ServerToMultiClientConfig is used to create a multi client configuration from existing server(s).
func SetupDebugging ¶
func SetupDebugging()
SetupDebugging can be added for development to tests that required additional debugging info.
func WaitUntilGrpcServerIsReady ¶
func WaitUntilGrpcServerIsReady( ctx context.Context, t *testing.T, conn grpc.ClientConnInterface, )
WaitUntilGrpcServerIsReady uses the health check API to check a service readiness.
Types ¶
type BroadcastStream ¶ added in v0.1.6
type BroadcastStream struct {
Broadcaster
ConnectionManager *ordererconn.ConnectionManager
}
BroadcastStream implements broadcast, with the addition of automatically signing the envelope.
func NewBroadcastStream ¶ added in v0.1.6
func NewBroadcastStream(ctx context.Context, config *ordererconn.Config) (*BroadcastStream, error)
NewBroadcastStream starts a new broadcast stream (non-production).
func (*BroadcastStream) Close ¶ added in v0.1.6
func (s *BroadcastStream) Close() error
Close is included to implement the io.Closer interface.
func (*BroadcastStream) CloseConnections ¶ added in v0.1.7
func (s *BroadcastStream) CloseConnections()
CloseConnections closes all the connections for the stream.
type Broadcaster ¶ added in v0.1.6
Broadcaster can be either CFT or BFT broadcast.
type CredentialsFactory ¶ added in v0.1.7
CredentialsFactory responsible for the creation of TLS certificates inside a TLSConfig for testing purposes by using the tls generation library of 'Hyperledger Fabric'.
func NewCredentialsFactory ¶ added in v0.1.7
func NewCredentialsFactory(t *testing.T) *CredentialsFactory
NewCredentialsFactory returns a CredentialsFactory with a new CA.
func (*CredentialsFactory) CreateClientCredentials ¶ added in v0.1.7
func (scm *CredentialsFactory) CreateClientCredentials(t *testing.T, tlsMode string) (connection.TLSConfig, string)
CreateClientCredentials creates a client key pair, Writing it to a temp testing folder and returns a connection.TLSConfig.
func (*CredentialsFactory) CreateServerCredentials ¶ added in v0.1.7
func (scm *CredentialsFactory) CreateServerCredentials( t *testing.T, tlsMode string, san ...string, ) (connection.TLSConfig, string)
CreateServerCredentials creates a server key pair given SAN(s) (Subject Alternative Name), Writing it to a temp testing folder and returns a connection.TLSConfig.
type GrpcServers ¶
type GrpcServers struct {
Servers []*grpc.Server
Configs []*connection.ServerConfig
}
GrpcServers holds the server instances and their respective configurations.
func StartGrpcServersForTest ¶
func StartGrpcServersForTest( ctx context.Context, t *testing.T, numService int, register func(*grpc.Server, int), ) *GrpcServers
StartGrpcServersForTest starts multiple GRPC servers with a default configuration.
func StartGrpcServersWithConfigForTest ¶
func StartGrpcServersWithConfigForTest( ctx context.Context, t *testing.T, sc []*connection.ServerConfig, register func(*grpc.Server, int), ) *GrpcServers
StartGrpcServersWithConfigForTest starts multiple GRPC servers with given configurations.
type RPCAttempt ¶ added in v0.1.7
RPCAttempt is a function returned by ServerStarter that contains the information needed to start a client connection and attempt an RPC call.
type ServerStarter ¶ added in v0.1.7
type ServerStarter func(t *testing.T, serverTLS connection.TLSConfig) RPCAttempt
ServerStarter is a function that receives a TLS configuration, starts the server, and returns a RPCAttempt function for initiating a client connection and attempting an RPC call.
type StatusRetriever ¶
type StatusRetriever interface {
GetTransactionsStatus(context.Context, *protoblocktx.QueryStatus, ...grpc.CallOption) (
*protoblocktx.TransactionsStatus, error,
)
}
StatusRetriever provides implementation retrieve status of given transaction identifiers.