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 ¶
- func TestApply(opts ...ceph.Option) ([]servicehook.Bootstrap, error)
- func TestClientState(client *ceph.ClientConfig) (owner *ceph.Container, created, ready, revoked bool)
- func TestCluster(control testcontainers.Container, c TestConfig) *ceph.Container
- func TestFaults(c *ceph.Container, kind faulthook.Kind) map[string]any
- func TestHeld(c *ceph.Container, kind overridehook.Kind) map[string]any
- func TestNetworkRemoved(c *ceph.Container) bool
- func TestOSDCount(c *ceph.Container) int
- func TestPrepare(osds int, noInitialOSDs bool, pools []ceph.PoolConfig, opts ...ceph.Option) ([]ceph.PoolConfig, []servicehook.Bootstrap, error)
- func TestRecordService(c *ceph.Container, name string, ctr testcontainers.Container)
- func TestReplaceOSDs(c *ceph.Container, osds map[int]*ceph.OSDContainer)
- func TestServices(c *ceph.Container) map[string]testcontainers.Container
- func TestSetCephFSImage(c *ceph.Container, image string)
- func TestSetCephVersion(c *ceph.Container, version string)
- func TestSetClosed(c *ceph.Container, closed bool)
- func TestSetConfig(c *ceph.Container, config []byte)
- func TestSetControlPlane(c *ceph.Container, control testcontainers.Container)
- func TestSetInitialOSDs(c *ceph.Container, osds int)
- func TestSetKeyring(c *ceph.Container, keyring []byte)
- func TestSetNetworkRemoved(c *ceph.Container, removed bool)
- func TestSetPoolDefaults(c *ceph.Container, replicas, minSize int)
- func TestSetStartupTimeout(c *ceph.Container, timeout time.Duration)
- func TestSwapFeatureClient(ctx context.Context, c *ceph.Container, current, next testcontainers.Container) (bool, error)
- type TestConfig
- type TestStateView
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 ¶
TestFaults snapshots the fault registry for unit tests. Call with the cluster mutex held.
func TestHeld ¶
TestHeld snapshots the handles that one override kind holds, for unit tests. Call with the cluster mutex held.
func TestNetworkRemoved ¶
TestNetworkRemoved reports whether a cluster's public bridge is marked removed, read without a lock.
func TestOSDCount ¶
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 ¶
TestSetCephFSImage selects the image of the CephFS role. It takes no lock.
func TestSetCephVersion ¶
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 ¶
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 ¶
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 ¶
TestSetInitialOSDs sets a cluster's initial OSD count. It takes no lock.
func TestSetKeyring ¶
TestSetKeyring replaces a cluster's recorded admin keyring. It takes no lock: hold ConfigMutex, or use a cluster no other goroutine uses.
func TestSetNetworkRemoved ¶
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 ¶
TestSetPoolDefaults sets the replica count and minimum size that pool defaults resolve to. It takes no lock.
func TestSetStartupTimeout ¶
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.