testutil

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides shared utilities for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BufferedPipe

func BufferedPipe() (net.Conn, net.Conn)

BufferedPipe is like net.Pipe(), but with internal buffering on writes. In practice, our connections are generally TCP connections, for which writes will not block.

Buffered writes may not be fully flushed to the peer when this connection is closed. Thus this pipe may not be suitable for tests which require strict adherence to the net.Conn contract.

Should probably be replaced with the standard library implementation if this happens: https://github.com/golang/go/issues/34502

Types

type SafeTestLogger

type SafeTestLogger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SafeTestLogger allows concurrent goroutines to safely log to a testing.T instance.

func NewSafeLogger

func NewSafeLogger(t *testing.T) *SafeTestLogger

NewSafeLogger wraps the testing.T instance in a SafeTestLogger.

func (*SafeTestLogger) Logf

func (l *SafeTestLogger) Logf(format string, a ...interface{})

Logf safely logs to the wrapped testing.T instance.

type TLSOrigin

type TLSOrigin struct {
	net.Listener

	sync.Mutex
	// contains filtered or unexported fields
}

TLSOrigin serves as a TLS origin, useful for proxying handshakes. Closes when the test completes.

func StartOrigin

func StartOrigin(t *testing.T, cfg *tls.Config) *TLSOrigin

StartOrigin starts a TLSOrigin. There is no need to call Close on the returned origin.

func (*TLSOrigin) DialContext

func (o *TLSOrigin) DialContext(ctx context.Context) (net.Conn, error)

DialContext dials the origin.

func (*TLSOrigin) DoPostHandshake

func (o *TLSOrigin) DoPostHandshake(f func(conn net.Conn) error)

DoPostHandshake can be used to configure post-handshake behavior.

Jump to

Keyboard shortcuts

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