testhelper

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testhelper gives unit tests of the ceph, rbd, cephfs, rgw, fault, override and internal packages the synthetic cluster constructor, the privileged state accessors and the registry snapshots they need. Only _test.go files import it: internal/tools/testsupportcheck fails when a non-test file does. The rest of the module has no Test* function or method and no test-config or test-state struct in a non-test file.

The package reaches unexported cluster state through one registered seam, hookreg.Test, which package ceph sets to its unitAccess value (ceph/unit_access.go). That value is not one of the hook values that production packages assert, and no other code links the helper to production internals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestApply

func TestApply(opts ...ceph.Option) ([]servicehook.Bootstrap, error)

TestApply applies options to empty settings and returns the service bootstraps they record.

func TestClientState

func TestClientState(client *ceph.ClientConfig) (owner *ceph.Container, created, ready, revoked bool)

TestClientState returns a client identity's owner and lifecycle flags.

func TestCluster

func TestCluster(control testcontainers.Container, c TestConfig) *ceph.Container

TestCluster builds a cluster value for unit tests: control runs the CLI.

func TestFaults

func TestFaults(c *ceph.Container, kind faulthook.Kind) map[string]any

TestFaults snapshots the fault registry for unit tests. Call with the cluster mutex held.

func TestHeld

func TestHeld(c *ceph.Container, kind overridehook.Kind) map[string]any

TestHeld snapshots the handles that one override kind holds, for unit tests. Call with the cluster mutex held.

func TestNetworkRemoved

func TestNetworkRemoved(c *ceph.Container) bool

TestNetworkRemoved reports whether a cluster's public bridge is marked removed, read without a lock.

func TestOSDCount

func TestOSDCount(c *ceph.Container) int

TestOSDCount is the number of OSD descriptors the cluster value owns, read without a lock.

func TestPrepare

func TestPrepare(osds int, noInitialOSDs bool, pools []ceph.PoolConfig, opts ...ceph.Option) ([]ceph.PoolConfig, []servicehook.Bootstrap, error)

TestPrepare validates an initial composition of osds OSDs and pools with opts applied, as Run does, and returns the resulting initial pool list and the prepared service bootstraps.

func TestRecordService added in v0.5.0

func TestRecordService(c *ceph.Container, name string, ctr testcontainers.Container)

TestRecordService records ctr as the named service container of the cluster value, which Terminate then stops, without the admission of a service start. It takes no lock: hold the mutex that TestState exposes, or use a cluster no other goroutine uses.

func TestReplaceOSDs

func TestReplaceOSDs(c *ceph.Container, osds map[int]*ceph.OSDContainer)

TestReplaceOSDs swaps the owned OSD descriptors of a cluster value for osds. It takes no lock: use it on a cluster no other goroutine uses, or while holding the mutex that TestState exposes.

func TestServices added in v0.5.0

func TestServices(c *ceph.Container) map[string]testcontainers.Container

TestServices returns a copy of the service containers the cluster value owns. It takes no lock: hold the mutex that TestState exposes, or use a cluster no other goroutine uses.

func TestSetCephFSImage

func TestSetCephFSImage(c *ceph.Container, image string)

TestSetCephFSImage selects the image of the CephFS role. It takes no lock.

func TestSetCephVersion

func TestSetCephVersion(c *ceph.Container, version string)

TestSetCephVersion replaces a cluster's recorded Ceph version. It takes no lock: use a cluster no other goroutine uses, or hold the mutex that TestState exposes.

func TestSetClosed

func TestSetClosed(c *ceph.Container, closed bool)

TestSetClosed sets or clears a cluster's closed flag. It takes no lock: hold the mutex that TestState exposes, or use a cluster no other goroutine uses.

func TestSetConfig

func TestSetConfig(c *ceph.Container, config []byte)

TestSetConfig replaces a cluster's recorded bootstrap configuration. It takes no lock: hold ConfigMutex, or use a cluster no other goroutine uses.

func TestSetControlPlane

func TestSetControlPlane(c *ceph.Container, control testcontainers.Container)

TestSetControlPlane replaces a cluster's control-plane container. It takes no lock: hold ControlMutex, or use a cluster no other goroutine uses.

func TestSetInitialOSDs

func TestSetInitialOSDs(c *ceph.Container, osds int)

TestSetInitialOSDs sets a cluster's initial OSD count. It takes no lock.

func TestSetKeyring

func TestSetKeyring(c *ceph.Container, keyring []byte)

TestSetKeyring replaces a cluster's recorded admin keyring. It takes no lock: hold ConfigMutex, or use a cluster no other goroutine uses.

func TestSetNetworkRemoved

func TestSetNetworkRemoved(c *ceph.Container, removed bool)

TestSetNetworkRemoved marks a cluster's public bridge as removed or not. It takes no lock: hold the mutex that TestState exposes, or use a cluster no other goroutine uses.

func TestSetPoolDefaults

func TestSetPoolDefaults(c *ceph.Container, replicas, minSize int)

TestSetPoolDefaults sets the replica count and minimum size that pool defaults resolve to. It takes no lock.

func TestSetStartupTimeout

func TestSetStartupTimeout(c *ceph.Container, timeout time.Duration)

TestSetStartupTimeout sets a cluster's startup timeout. It takes no lock.

func TestSwapFeatureClient added in v0.5.0

func TestSwapFeatureClient(ctx context.Context, c *ceph.Container, current, next testcontainers.Container) (bool, error)

TestSwapFeatureClient publishes next as a cluster's started client container (the one ClientContainer returns for a separate client image) when current is still the published one, and reports whether it did. It takes the client's startup lock itself, so it may be used on a live cluster; it does nothing for an aggregate image, whose client is the control-plane container.

Types

type TestConfig

type TestConfig struct {
	StartupTimeout time.Duration
	Closed         bool
	HostNetwork    bool
	PublicAddress  string
	NetworkName    string
	// OSDs adds owned OSD descriptors 0..OSDs-1 whose container is control
	// and whose CRUSH location is OSDPlacement.
	OSDs         int
	OSDPlacement ceph.OSDConfig
	// MemStore selects the OSDMemStore object store instead of BlueStore.
	MemStore bool
	// MessengerMode selects the bootstrap messenger mode.
	MessengerMode ceph.MessengerMode
	// Images selects the role images; nil means one aggregate image.
	Images *ceph.ImageSet
}

TestConfig selects the settings of a unit-test cluster value.

type TestStateView

type TestStateView struct {
	Mutex        *sync.Mutex
	ControlMutex *sync.RWMutex
	ConfigMutex  *sync.RWMutex
	PortLeases   int
}

TestStateView points at a cluster's locks for unit tests. PortLeases is a count taken when TestState is called. The closed flag, the control plane, the options, the bootstrap record and the bridge-removal flag are written through the TestSet* functions.

func TestState

func TestState(c *ceph.Container) TestStateView

TestState exposes a cluster's lock identities to unit tests.

Jump to

Keyboard shortcuts

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