testutil

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Set to true to enable advanced networking tests such as those that require access to all network interfaces
	// and try to open ports that are accessible to requests originating from outside of the machine or tests
	// that evaluate network performance against a baseline (these are unreliable on CI machines).
	// This is disabled by default because on Windows it causes a security prompt every time the tests are run.
	DCP_TEST_ENABLE_ADVANCED_NETWORKING = "DCP_TEST_ENABLE_ADVANCED_NETWORKING"

	// Set to true to enable advanced certificate file tests such as those that require openssl installed to
	// verify behavior.
	DCP_TEST_ENABLE_ADVANCED_CERTIFICATES = "DCP_TEST_ENABLE_ADVANCED_CERTIFICATES"

	// Set to true to enable tests that require real container orchestrator (Docker or Podman).
	DCP_TEST_ENABLE_TRUE_CONTAINER_ORCHESTRATOR = "DCP_TEST_ENABLE_TRUE_CONTAINER_ORCHESTRATOR"

	// Used by VS Code to disable skipping tests when they are run with the debugger.
	DCP_TEST_VS_CODE_DEBUGGER = "DCP_TEST_VS_CODE_DEBUGGER"
)

Variables

This section is empty.

Functions

func AsByteTimelineEntries

func AsByteTimelineEntries(b ...byte) []testReaderTimelineEntry

func AsErrorTimelineEntry

func AsErrorTimelineEntry(err error) testReaderTimelineEntry

func CreateTestSessionDir

func CreateTestSessionDir() (string, error)

Creates a session directory for use in tests.

func FindAllMatching

func FindAllMatching(ss []string, re *regexp.Regexp) [][]string

FindAllMatching tries the passed regular expression on all strings in the passed slice and returns the result for re.FindStringSubmatch() for each string in the slice that matches. For each match, the slice returned will contain the full match, followed by all captured groups (subexpressions).

func GetRandLetters

func GetRandLetters(t *testing.T, count int) string

func GetTestContext

func GetTestContext(t *testing.T, testTimeout time.Duration) (context.Context, context.CancelFunc)

func LengthNotChanging

func LengthNotChanging[S ~[]E, E any](ctx context.Context, s *S, period time.Duration, numPeriods uint, lock sync.Locker) error

Verify that the length of a slice does not change over several periods of time. The function is taking a pointer to the slice because the slice might be manipulated by other goroutines.

func NewLogForTesting

func NewLogForTesting(name string) logr.Logger

func SkipIfNotEnableAdvancedNetworking

func SkipIfNotEnableAdvancedNetworking(t *testing.T)

func SkipIfNotEnabledAdvancedCertificates

func SkipIfNotEnabledAdvancedCertificates(t *testing.T)

func SkipIfTrueContainerOrchestratorNotEnabled

func SkipIfTrueContainerOrchestratorNotEnabled(t *testing.T)

func TestTempDir

func TestTempDir() string

Returns a temporary directory path for use in tests. If session folder is set in the environment, returns that. Otherwise, returns the temporary directory root path.

func TestTempRoot

func TestTempRoot() string

Returns temporary directory root path for use in tests. Agents running tests in CI pipelines often require that tests use temporary directory that is different from what TEMP or TMPDIR environment variables point to. This function takes care of that.

Types

type BufferWriter

type BufferWriter struct {
	// contains filtered or unexported fields
}

func NewBufferWriter

func NewBufferWriter() *BufferWriter

func (*BufferWriter) AddTarget

func (bw *BufferWriter) AddTarget(t io.Writer) error

func (*BufferWriter) Bytes

func (bw *BufferWriter) Bytes() []byte

func (*BufferWriter) Chunks

func (bw *BufferWriter) Chunks() []Chunk

func (*BufferWriter) ChunksLen

func (bw *BufferWriter) ChunksLen() int

func (*BufferWriter) Close

func (bw *BufferWriter) Close() error

func (*BufferWriter) Closed

func (bw *BufferWriter) Closed() <-chan struct{}

func (*BufferWriter) FailNextSync

func (bw *BufferWriter) FailNextSync(err error)

FailNextSync causes the next Sync operation to fail with an error. After the failure, subsequent syncs will succeed normally.

func (*BufferWriter) FailNextWrite

func (bw *BufferWriter) FailNextWrite(err error)

FailNextWrite causes the next Write operation to fail with an error. After the failure, subsequent writes will succeed normally.

func (*BufferWriter) Lines

func (bw *BufferWriter) Lines(sep []byte) [][]byte

func (*BufferWriter) Sync

func (bw *BufferWriter) Sync() error

func (*BufferWriter) Write

func (bw *BufferWriter) Write(p []byte) (int, error)

type Chunk

type Chunk struct {
	Offset    int
	Length    int
	Timestamp time.Time
}

type MockLoggerSink

type MockLoggerSink struct {
	mock.Mock
}

func NewMockLoggerSink

func NewMockLoggerSink() *MockLoggerSink

func (*MockLoggerSink) EnableErrorCall

func (m *MockLoggerSink) EnableErrorCall()

func (*MockLoggerSink) Enabled

func (m *MockLoggerSink) Enabled(level int) bool

func (*MockLoggerSink) Error

func (m *MockLoggerSink) Error(err error, msg string, keysAndValues ...interface{})

func (*MockLoggerSink) Info

func (m *MockLoggerSink) Info(level int, msg string, keysAndValues ...interface{})

func (*MockLoggerSink) Init

func (m *MockLoggerSink) Init(info logr.RuntimeInfo)

func (*MockLoggerSink) WithName

func (m *MockLoggerSink) WithName(name string) logr.LogSink

func (*MockLoggerSink) WithValues

func (m *MockLoggerSink) WithValues(keysAndValues ...interface{}) logr.LogSink

type TestReader

type TestReader struct {
	// contains filtered or unexported fields
}

func NewTestReader

func NewTestReader() *TestReader

func (*TestReader) AddEntry

func (tr *TestReader) AddEntry(entries ...testReaderTimelineEntry)

func (*TestReader) Close

func (tr *TestReader) Close() error

func (*TestReader) Read

func (tr *TestReader) Read(p []byte) (int, error)

type ThreadSafeBuffer added in v0.22.8

type ThreadSafeBuffer struct {
	// contains filtered or unexported fields
}

ThreadSafeBuffer is an io.ReadWriter that is safe for concurrent use by multiple goroutines. It uses an internal bytes.Buffer to store data and a sync.Mutex to ensure thread safety.

func NewThreadSafeBuffer added in v0.22.8

func NewThreadSafeBuffer() *ThreadSafeBuffer

NewThreadSafeBuffer creates and returns a new ThreadSafeBuffer instance.

func (*ThreadSafeBuffer) Read added in v0.22.8

func (b *ThreadSafeBuffer) Read(p []byte) (n int, err error)

func (*ThreadSafeBuffer) Write added in v0.22.8

func (b *ThreadSafeBuffer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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