testutil

package
v1.0.0-beta.26 Latest Latest
Warning

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

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

Documentation

Overview

Package testutil builds real local snapshot and content stores for transfer tests. The stores need no privileges: see inplace.go for what that costs.

Index

Constants

View Source
const Namespace = "snapshot-transfer-test"

Variables

View Source
var FileTime = time.Unix(1700000000, 0).UTC()

Functions

func CheckFile

func CheckFile(t testing.TB, ref bkcache.ImmutableRef, name, want string)

func OverlayTree

func OverlayTree(t testing.TB, ref bkcache.ImmutableRef) map[string]string

OverlayTree returns the tree a committed snapshot of an overlay store shows, merged from its layers' directories as overlayfs merges them, without mounting: each path, with its kind and permissions, a file's content and a symlink's target. A whiteout hides the path below it, and an opaque directory everything below it.

func Root

func Root(t testing.TB, ref bkcache.ImmutableRef) string

Root returns the directory behind a committed snapshot of this store, for a test that reads the bytes it expects there.

Types

type Provider

type Provider struct {
	content.InfoReaderProvider
	Reads      atomic.Int64
	BeforeRead func(context.Context, ocispecs.Descriptor) error
}

func (*Provider) ReaderAt

func (p *Provider) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error)

type Store

type Store struct {
	Manager   bkcache.SnapshotManager
	Content   *containerdsnapshot.Store
	Snapshots bkcache.Snapshotter
	Leases    leases.Manager
	DB        *metadata.DB
	Applies   atomic.Int64
	// ContentRead counts the bytes read from the content store.
	ContentRead atomic.Int64
	Diffs       atomic.Int64
	BeforeWrite func([]byte) error
	BeforeApply func(context.Context, ocispecs.Descriptor) error
	BeforeDiff  func(context.Context) error
	// BeforeSnapshotUpdate runs before each snapshot label update.
	BeforeSnapshotUpdate func(context.Context, ctdsnapshots.Info) error
	// BeforeStat runs before each snapshot Stat the manager makes.
	BeforeStat func(ctx context.Context, key string)
	// LeaseCommitErr, when set, rolls back each transaction the manager
	// makes through SnapshotManagerOpt.MetadataDB and returns it.
	LeaseCommitErr error
	// Builtin, when set before the manager is (re)opened, plays the engine's
	// builtin image store for chain imports.
	Builtin     content.InfoReaderProvider
	BeforeAdd   func(context.Context, leases.Lease, leases.Resource) error
	AfterAdd    func(context.Context, leases.Lease, leases.Resource)
	AfterCreate func(leases.Lease)

	// SharedMountLinger and MaxIdleSharedMounts, when set before the manager
	// is (re)opened, bound its idle shared read-only mounts.
	SharedMountLinger   time.Duration
	MaxIdleSharedMounts int
	// LocalMounts and LocalUnmounts count the shared read-only mounts made
	// and unmounted; they are made in place, without privileges.
	LocalMounts   atomic.Int64
	LocalUnmounts atomic.Int64
	// BeforeLocalUnmount runs before each of those unmounts.
	BeforeLocalUnmount func()
	// contains filtered or unexported fields
}

func NewOverlayStore

func NewOverlayStore(t testing.TB) *Store

NewOverlayStore builds a store on containerd's overlay snapshotter and its own applier, as the engine runs: chain imports onto it apply their layers apart and rebase them. The applier writes an overlay snapshot's directory in place and mounts nothing, so imports of layers with no whiteouts need no privileges.

Whiteouts are device nodes, which an overlay filesystem such as a test container's own /tmp refuses to hold; with the privilege to mount, the store is then kept on a tmpfs, as an engine keeps its state on a filesystem of its own. CanMakeWhiteouts and CanMakeOpaque say whether the store can hold whiteouts and opaque directories. Only importing onto it is supported: Build, Root and diffs expect a native store's directories. OverlayTree reads what it imported.

func NewStore

func NewStore(t testing.TB) *Store

func (*Store) Build

func (s *Store) Build(t testing.TB, parent bkcache.ImmutableRef, name, value string) (bkcache.ImmutableRef, string)

Build writes through an ordinary mutable ref, commits, and keeps an ordinary owner lease. The caller can release that owner independently of returned refs.

func (*Store) BuildWith

func (s *Store) BuildWith(t testing.TB, parent bkcache.ImmutableRef, write func(root string)) (bkcache.ImmutableRef, string)

BuildWith is Build with write making the layer's changes under its root. A nil write makes no changes.

func (*Store) CanMakeOpaque

func (s *Store) CanMakeOpaque() error

func (*Store) CanMakeWhiteouts

func (s *Store) CanMakeWhiteouts() error

CanMakeWhiteouts reports why the store can't hold the device nodes overlay whiteouts are, or nil when it can, and CanMakeOpaque why it can't mark a directory opaque, which takes CAP_SYS_ADMIN.

func (*Store) GC

func (s *Store) GC(t testing.TB)

func (*Store) Reload

func (s *Store) Reload(t testing.TB)

func (*Store) WithBuiltin

func (s *Store) WithBuiltin(t testing.TB, provider content.InfoReaderProvider)

WithBuiltin reopens the manager with provider as the builtin image store, keeping the persistent metadata.

func (*Store) WithSharedMounts

func (s *Store) WithSharedMounts(t testing.TB, linger time.Duration, maxIdle int)

WithSharedMounts reopens the manager with the given bounds on its idle shared read-only mounts, keeping the persistent metadata.

Jump to

Keyboard shortcuts

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