testutils

package
v0.0.0-...-81a4c79 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsPtr

func AsPtr[T any](i T) *T

AsPtr returns the value as a pointer.

func Check

func Check(err error)

Check checks the error and panics if not nil.

func Must

func Must[T any](val T, err error) T

Must checks the error and panics if not nil.

func WithCancel

func WithCancel(d DeferFunc, f func()) (DeferFunc, CancelFunc)

WithCancel returns a deferrable function that can be cancelled.

Types

type CancelFunc

type CancelFunc func()

CancelFunc is a cancel function.

type DeferFunc

type DeferFunc func()

DeferFunc is a deferrable function.

type File

type File struct {
	// Path is the path to the file.
	Path string

	// Contents are the file contents.
	Contents []byte

	// Mode is the file permissions mode.
	Mode os.FileMode
}

File is a test file.

type TempDir

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

TempDir is a temporary directory which is set up with a directory structure with some files for testing.

func NewTempDir

func NewTempDir(files []*File) *TempDir

NewTempDir creates a new TempDir. This creates a new temporary directory and fills it with the files given. Intermediate directories are created automatically with 0700 permissions. This function panics if an error occurs when creating the files.

func (*TempDir) Cleanup

func (d *TempDir) Cleanup()

Cleanup deletes the test directory.

func (*TempDir) Dir

func (d *TempDir) Dir() string

Dir returns the path to the directory.

type TestRepo

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

TestRepo is a repo created in a temporary directory.

func NewTestRepo

func NewTestRepo(dir, author, email string, files []*File) *TestRepo

NewTestRepo creates a new TestRepo with the given files committed into a single commit in the repo.

func (*TestRepo) Dir

func (r *TestRepo) Dir() string

Dir returns the path to the repo root directory.

func (*TestRepo) Repository

func (r *TestRepo) Repository() *git.Repository

Repository returns the git repository.

Jump to

Keyboard shortcuts

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