testutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 32 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// HelloArchiveURL points to an OCI archive of `hello-world`.
	// Exported from `docker.io/library/hello-world@sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec` .
	// See https://github.com/AkihiroSuda/test-oci-archives/releases/tag/v20210101
	HelloArchiveURL = "https://github.com/AkihiroSuda/test-oci-archives/releases/download/v20210101/hello-world.tar.gz"
	// HelloArchiveDigest is the digest of the archive.
	HelloArchiveDigest = "sha256:5aa022621c4de0e941ab2a30d4569c403e156b4ba2de2ec32e382ae8679f40e1"
)
View Source
const (
	BuildKitVersion = "v0.8.1"
)

Variables

View Source
var TestingL = log.New(os.Stdout, "testing: ", log.Ldate|log.Ltime)

TestingL is a Logger instance used during testing. This allows tests to prints logs in realtime.

Functions

func ApplyTextTemplate

func ApplyTextTemplate(temp string, config interface{}) (string, error)

ApplyTextTemplate applies the config to the specified template.

func ApplyTextTemplateErr

func ApplyTextTemplateErr(temp string, conf interface{}) ([]byte, error)

ApplyTextTemplateErr applies the config to the specified template.

func BuildTar

func BuildTar(ents []TarEntry, opts ...BuildTarOption) io.Reader

BuildTar builds a tar given a list of tar entries and returns an io.Reader

func BuildTarGz

func BuildTarGz(ents []TarEntry, compressionLevel int, opts ...BuildTarOption) io.Reader

BuildTarGz builds a tar.gz given a list of tar entries and returns an io.Reader

func BuildTarZstd

func BuildTarZstd(ents []TarEntry, compressionLevel int, opts ...BuildTarOption) io.Reader

BuildTarZstd builds a tar blob with zstd compression.

func CopyInDir

func CopyInDir(sh *shell.Shell, from, to string) error

CopyInDir copies a directory into the specified location in the specified execution environment.

func EnsureHello

func EnsureHello(ctx context.Context) (*ocispec.Descriptor, content.Store, error)

EnsureHello creates a temp content store and ensures `hello-world` image from HelloArchiveURL into the store.

func GetFilesAndContentsWithinTarGz

func GetFilesAndContentsWithinTarGz(tarGz string) (map[string][]byte, []string, error)

GetFilesAndContentsWithinTarGz takes a path to a targz archive and returns a list of its files and their contents

func GetProjectRoot

func GetProjectRoot() (string, error)

GetProjectRoot returns the path to the directory where the source code of this project reside.

func KillMatchingProcess

func KillMatchingProcess(sh *shell.Shell, psLinePattern string) error

KillMatchingProcess kills processes that "ps" line matches the specified pattern in the specified execution environment.

func RandomByteData

func RandomByteData(size int64) []byte

RandomByteData returns a byte slice with `size` populated with random generated data

func RandomByteDataRange

func RandomByteDataRange(minBytes int, maxBytes int) []byte

RandomByteDataRange returns a byte slice with `size` between minBytes and maxBytes exclusive populated with random data

func RandomDigest

func RandomDigest() string

RandomDigest generates a random digest from a random sequence of bytes

func RandomUInt64

func RandomUInt64() (uint64, error)

RandomUInt64 returns a random uint64 value generated from /dev/uramdom.

func StreamTestingLogToFile

func StreamTestingLogToFile(destPath string) (func() error, error)

StreamTestingLogToFile allows TestingL to stream the logging output to the speicified file.

func TempDir

func TempDir(sh *shell.Shell) (string, error)

TempDir creates a temporary directory in the specified execution environment.

func TestingLogDest

func TestingLogDest() (io.Writer, io.Writer)

TestingLogDest returns Writes of Testing.T.

func WriteFileContents

func WriteFileContents(sh *shell.Shell, name string, content []byte, mode uint32) error

WriteFileContents creates a file at the specified location in the specified execution environment and writes the specified contents to that file.

func WriteTarToTempFile

func WriteTarToTempFile(tarNamePattern string, tarReader io.Reader) (string, []byte, error)

WriteTarToTempFile writes the contents of a tar archive to a specified path and return the temp filename and the tar data (as []byte).

It's the caller's responsibility to remove the genreated temp file.

Types

type BuildTarOption

type BuildTarOption func(o *BuildTarOptions)

BuildTarOption is an option used during building blob.

func WithGzipComment

func WithGzipComment(comment string) BuildTarOption

func WithGzipExtra

func WithGzipExtra(extra []byte) BuildTarOption

func WithGzipFilename

func WithGzipFilename(filename string) BuildTarOption

func WithPrefix

func WithPrefix(prefix string) BuildTarOption

WithPrefix is an option to add a prefix string to each file name (e.g. "./", "/", etc.)

type BuildTarOptions

type BuildTarOptions struct {

	// Prefix is the prefix string need to be added to each file name (e.g. "./", "/", etc.)
	Prefix string

	GzipComment  string
	GzipFilename string
	GzipExtra    []byte
}

BuildTarOptions is a set of options used during building blob.

type DirectoryBuildTarOption

type DirectoryBuildTarOption func(o *dirOpts)

DirectoryBuildTarOption is an option for a directory entry.

func WithDirModTime

func WithDirModTime(modTime time.Time) DirectoryBuildTarOption

WithDirModTime specifies the modtime of the dir.

func WithDirMode

func WithDirMode(mode os.FileMode) DirectoryBuildTarOption

WithDirMode specifies the mode of the directory.

func WithDirOwner

func WithDirOwner(uid, gid int) DirectoryBuildTarOption

WithDirOwner specifies the owner of the directory.

func WithDirXattrs

func WithDirXattrs(xattrs map[string]string) DirectoryBuildTarOption

WithDirXattrs specifies the extended attributes of the directory.

type FileBuildTarOption

type FileBuildTarOption func(o *fileOpts)

FileBuildTarOption is an option for a file entry.

func WithFileModTime

func WithFileModTime(modTime time.Time) FileBuildTarOption

WithFileModTime specifies the modtime of the file.

func WithFileMode

func WithFileMode(mode os.FileMode) FileBuildTarOption

WithFileMode specifies the mode of the file.

func WithFileOwner

func WithFileOwner(uid, gid int) FileBuildTarOption

WithFileOwner specifies the owner of the file.

func WithFileXattrs

func WithFileXattrs(xattrs map[string]string) FileBuildTarOption

WithFileXattrs specifies the extended attributes of the file.

type RemoteSnapshotMonitor

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

RemoteSnapshotMonitor scans log of soci snapshotter and provides the way to check if all snapshots are prepared as remote snpashots.

func NewRemoteSnapshotMonitor

func NewRemoteSnapshotMonitor(r shell.Reporter, stdout, stderr io.Reader) *RemoteSnapshotMonitor

NewRemoteSnapshotMonitor creates a new instance of RemoteSnapshotMonitor that scans logs streamed from the specified io.Reader.

func (*RemoteSnapshotMonitor) CheckAllRemoteSnapshots

func (m *RemoteSnapshotMonitor) CheckAllRemoteSnapshots(t *testing.T)

CheckAllRemoteSnapshots checks if the scanned log reports that all snapshots are prepared as remote snapshots.

func (*RemoteSnapshotMonitor) ScanLog

func (m *RemoteSnapshotMonitor) ScanLog(inputR io.Reader)

ScanLog scans the log streamed from the specified io.Reader.

type RemoteSnapshotPreparedLogLine

type RemoteSnapshotPreparedLogLine struct {
	RemoteSnapshotPrepared string `json:"remote-snapshot-prepared"`
}

type TarEntry

type TarEntry interface {
	AppendTar(tw *tar.Writer, opts BuildTarOptions) error
}

TarEntry is an entry of tar.

func Blockdev

func Blockdev(name string, major, minor int64) TarEntry

Blockdev is a block device entry

func Chardev

func Chardev(name string, major, minor int64) TarEntry

Chardev is a character device entry

func Dir

func Dir(name string, opts ...DirectoryBuildTarOption) TarEntry

Dir is a directory entry

func Fifo

func Fifo(name string) TarEntry

Fifo is a fifo entry

func File

func File(name, contents string, opts ...FileBuildTarOption) TarEntry

File is a regular file entry

func Link(name, linkname string) TarEntry

Link is a hard-link entry

func Symlink(name, target string) TarEntry

Symlink is a symlink entry

type TestingReporter

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

TestingReporter is an implementation of dockershell.Reporter backed by testing.T and TestingL.

func NewTestingReporter

func NewTestingReporter(t *testing.T) *TestingReporter

NewTestingReporter returns a new TestingReporter instance for the specified testing.T.

func (*TestingReporter) Errorf

func (r *TestingReporter) Errorf(format string, v ...interface{})

Errorf prints the provided message to TestingL and stops the test using testing.T.Fatalf.

func (*TestingReporter) Logf

func (r *TestingReporter) Logf(format string, v ...interface{})

Logf prints the provided message to TestingL testing.T.

func (*TestingReporter) Stderr

func (r *TestingReporter) Stderr() io.Writer

Stderr returns the writer to TestingL as stderr. This enables to print command logs realtime.

func (*TestingReporter) Stdout

func (r *TestingReporter) Stdout() io.Writer

Stdout returns the writer to TestingL as stdout. This enables to print command logs realtime.

Jump to

Keyboard shortcuts

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