package testutil

import "github.com/containerd/stargz-snapshotter/util/testutil"

Index

Constants

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"
)

Functions

func BuildEStargz

func BuildEStargz(ents []TarEntry, opts ...BuildEStargzOption) (*io.SectionReader, digest.Digest, error)

func BuildTar

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

BuildTar builds a tar blob

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 RandomBytes

func RandomBytes(t *testing.T, n int) []byte

RandomBytes returns the specified number of random bytes

Types

type BuildEStargzOption

type BuildEStargzOption func(o *buildEStargzOptions) error

func WithBuildTarOptions

func WithBuildTarOptions(to ...BuildTarOption) BuildEStargzOption

WithBuildTarOptions option specifies the options for tar creation

func WithEStargzOptions

func WithEStargzOptions(eo ...estargz.Option) BuildEStargzOption

WithEStargzOptions specifies options for estargz lib

type BuildTarOption

type BuildTarOption func(o *BuildTarOptions)

BuildTarOption is an option used during building blob.

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
}

BuildTarOptions is a set of options used during building blob.

type Compression

type Compression interface {
	estargz.Compressor
	estargz.Decompressor

	// DecompressTOC decompresses the passed blob and returns a reader of TOC JSON.
	// This is needed to be used from metadata pkg
	DecompressTOC(io.Reader) (tocJSON io.ReadCloser, err error)
}

type CompressionFactory

type CompressionFactory func() Compression

func ExternalTOCGzipCompressionWithLevel

func ExternalTOCGzipCompressionWithLevel(compressionLevel int) CompressionFactory

func GzipCompressionWithLevel

func GzipCompressionWithLevel(compressionLevel int) CompressionFactory

func ZstdCompressionWithLevel

func ZstdCompressionWithLevel(compressionLevel zstd.EncoderLevel) CompressionFactory

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 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 regilar 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

Source Files

compression.go ensurehello.go estargz.go tar.go util.go

Version
v0.16.3 (latest)
Published
Dec 12, 2024
Platform
linux/amd64
Imports
21 packages
Last checked
2 weeks ago

Tools for package owners.