testutil

package
v0.0.0-...-cd7ca46 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: 11 Imported by: 0

Documentation

Overview

Package testutil provides utilities for testing the network package.

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for running a server.
	DefaultTimeout = time.Minute
)

Variables

This section is empty.

Functions

func GetDockerPID

func GetDockerPID(dockerName string) (int64, error)

GetDockerPID returns the PID of a docker container.

func RunDockerServer

func RunDockerServer(t testing.TB, serverName, dockerPath string, env []string, serverStartRegex *regexp.Regexp, timeout time.Duration, retryCount int) error

RunDockerServer is a template for running a protocols server in a docker. - serverName is a friendly name of the server we are setting (AMQP, mongo, etc.). - dockerPath is the path for the docker-compose. - env is any environment variable required for running the server. - serverStartRegex is a regex to be matched on the server logs to ensure it started correctly.

func RunHostServer

func RunHostServer(t *testing.T, command []string, env []string, serverStartRegex *regexp.Regexp) bool

RunHostServer is a template for running a command on the Host. - command is the path for the command to execute. - env is any environment variable required for running the server. - serverStartRegex is a regex to be matched on the server logs to ensure it started correctly. return true on success

Types

type PatternScanner

type PatternScanner struct {

	// Once we've found the correct log, we should notify the caller.
	DoneChan chan struct{}
	// contains filtered or unexported fields
}

PatternScanner is a helper to scan logs for a given pattern.

func NewScanner

func NewScanner(pattern *regexp.Regexp, doneChan chan struct{}) *PatternScanner

NewScanner returns a new instance of PatternScanner.

func (*PatternScanner) PrintLogs

func (ps *PatternScanner) PrintLogs(t testing.TB)

PrintLogs writes the captured logs into the test logger.

func (*PatternScanner) Write

func (ps *PatternScanner) Write(p []byte) (n int, err error)

Write implemented io.Writer to be used as a callback for log/string writing. Once we find a match in for the given pattern, we notify the caller.

Jump to

Keyboard shortcuts

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