testutil

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TestProjectName = &name.Project{
		ProjectID: "test-project",
	}

	TestRecordName = &name.Record{
		ProjectID: "test-project",
		RecordID:  "test-record",
	}

	TestFileName = &name.File{
		ProjectID: "test-project",
		RecordID:  "test-record",
		Filename:  "test.txt",
	}
)

Common test names

Functions

func AssertFileContent

func AssertFileContent(t *testing.T, path string, expected []byte)

AssertFileContent checks that a file contains the expected content.

func CaptureOutput

func CaptureOutput(t *testing.T, fn func()) (stdout, stderr string)

CaptureOutput captures stdout and stderr for testing command output.

func CopyFile

func CopyFile(t *testing.T, src, dst string)

CopyFile copies a file from src to dst.

func CreateTempFile

func CreateTempFile(t *testing.T, dir, pattern string, content []byte) string

CreateTempFile creates a temporary file with the given content.

func CreateTestFileTree

func CreateTestFileTree(t *testing.T, baseDir string, files map[string][]byte)

CreateTestFileTree creates a directory structure with files for testing.

func CreateTestLabel

func CreateTestLabel(displayName string) *openv1alpha1resource.Label

CreateTestLabel creates a test label with the given display name.

func RequireEnv

func RequireEnv(t *testing.T, key string) string

RequireEnv skips the test if the given environment variable is not set.

func SkipIfShort

func SkipIfShort(t *testing.T)

SkipIfShort skips the test if running with -short flag.

func TempDir

func TempDir(t *testing.T) string

TempDir creates a temporary directory for testing and ensures cleanup.

func TestContext

func TestContext(t *testing.T) context.Context

TestContext returns a context with a reasonable timeout for tests.

Types

type FileBuilder

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

FileBuilder helps create test File objects.

func NewFileBuilder

func NewFileBuilder() *FileBuilder

NewFileBuilder creates a new FileBuilder with defaults.

func (*FileBuilder) Build

Build returns the built File.

func (*FileBuilder) WithFilename

func (b *FileBuilder) WithFilename(filename string) *FileBuilder

WithFilename sets the filename.

func (*FileBuilder) WithName

func (b *FileBuilder) WithName(name string) *FileBuilder

WithName sets the file resource name.

func (*FileBuilder) WithSha256

func (b *FileBuilder) WithSha256(sha256 string) *FileBuilder

WithSha256 sets the file SHA256.

func (*FileBuilder) WithSize

func (b *FileBuilder) WithSize(size int64) *FileBuilder

WithSize sets the file size.

type ProjectBuilder

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

ProjectBuilder helps create test Project objects.

func NewProjectBuilder

func NewProjectBuilder() *ProjectBuilder

NewProjectBuilder creates a new ProjectBuilder with defaults.

func (*ProjectBuilder) Build

Build returns the built Project.

func (*ProjectBuilder) WithDisplayName

func (b *ProjectBuilder) WithDisplayName(displayName string) *ProjectBuilder

WithDisplayName sets the project display name.

func (*ProjectBuilder) WithName

func (b *ProjectBuilder) WithName(name string) *ProjectBuilder

WithName sets the project name.

type RecordBuilder

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

RecordBuilder helps create test Record objects.

func NewRecordBuilder

func NewRecordBuilder() *RecordBuilder

NewRecordBuilder creates a new RecordBuilder with defaults.

func (*RecordBuilder) Build

Build returns the built Record.

func (*RecordBuilder) WithDescription

func (b *RecordBuilder) WithDescription(desc string) *RecordBuilder

WithDescription sets the record description.

func (*RecordBuilder) WithDevice

func (b *RecordBuilder) WithDevice(deviceName string) *RecordBuilder

WithDevice sets the record device.

func (*RecordBuilder) WithLabels

func (b *RecordBuilder) WithLabels(labels []*openv1alpha1resource.Label) *RecordBuilder

WithLabels sets the record labels.

func (*RecordBuilder) WithName

func (b *RecordBuilder) WithName(name string) *RecordBuilder

WithName sets the record name.

func (*RecordBuilder) WithTitle

func (b *RecordBuilder) WithTitle(title string) *RecordBuilder

WithTitle sets the record title.

Jump to

Keyboard shortcuts

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