dbustest

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dbustest runs private dbus-daemons for tests, so services that export or call D-Bus objects are exercised over a real bus without touching the user's session or system bus. Each bus is configured from a file the helper writes itself, so a test needs dbus-daemon on PATH and nothing in /etc, where a distro's session.conf may be absent (NixOS, minimal containers).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchRules

func MatchRules(t testing.TB, conn *dbus.Conn) []string

MatchRules are the match rules the bus holds for conn, as the bus prints them (org.freedesktop.DBus.Debug.Stats): what a test reads to see that a watch left a shared connection as it found it.

func SessionConn

func SessionConn(t testing.TB) *dbus.Conn

SessionConn opens a connection to the session bus the test pointed at a private bus (Session or UseAsSessionBus), closed at cleanup.

func SocketPath

func SocketPath(t testing.TB) string

SocketPath is a fresh bus socket path, removed with the test, in a directory short enough for AF_UNIX's 108-byte sun_path (sockdir). A bus stopped there can be followed by another at the same path, which a client dialing that fixed address sees as the bus restarting.

Types

type Bus

type Bus struct {
	// Address is the bus address, for dbus.Connect or
	// DBUS_SESSION_BUS_ADDRESS.
	Address string
	// contains filtered or unexported fields
}

Bus is one private bus.

func Session

func Session(t testing.TB) *Bus

Session starts a private bus and makes it the test's session bus, for daemon and CLI halves that both dial the session bus.

func Start

func Start(t testing.TB) *Bus

Start launches a dbus-daemon on a fresh socket (SocketPath) for the test and stops it at cleanup. A missing dbus-daemon fails the test: the dev shell provides one.

func StartAt

func StartAt(t testing.TB, sock string) *Bus

StartAt launches a dbus-daemon bound to sock for the test and stops it at cleanup. The bus accepts connections once StartAt returns.

func (*Bus) Conn

func (b *Bus) Conn(t testing.TB) *dbus.Conn

Conn opens a new authenticated connection to the bus, closed at cleanup. Each call is a distinct peer with its own unique name.

func (*Bus) Stop

func (b *Bus) Stop(t testing.TB)

Stop terminates the daemon and waits for it to exit, so a bus started next at the same socket does not race a dying one; connections to it see the bus go away. Stopping again does nothing.

func (*Bus) UseAsSessionBus

func (b *Bus) UseAsSessionBus(t testing.TB)

UseAsSessionBus points DBUS_SESSION_BUS_ADDRESS at the bus for the test, for code that dials the session bus itself.

func (*Bus) UseAsSystemBus

func (b *Bus) UseAsSystemBus(t testing.TB)

UseAsSystemBus points DBUS_SYSTEM_BUS_ADDRESS at the bus for the test, for code that dials the system bus itself.

type Pipe

type Pipe struct {
	Write dbus.UnixFD
	// contains filtered or unexported fields
}

Pipe proves that a descriptor a test sends over D-Bus is closed by everyone it reaches: Write is the write end of a pipe, to send, and its read end hangs up only once no copy of Write is open anywhere in the process.

func NewPipe

func NewPipe(t testing.TB) *Pipe

NewPipe opens a Pipe, closed at cleanup.

func (*Pipe) RequireEveryCopyClosed

func (p *Pipe) RequireEveryCopyClosed(t testing.TB)

RequireEveryCopyClosed closes Write and fails the test unless every copy of it the bus handed out in the process is closed as well within a liveness bound.

type Var

type Var[T any] struct {
	// contains filtered or unexported fields
}

Var is state a bus handler writes and the test reads. A method call and its reply cross a socket, which the race detector cannot see as ordering, so a plain captured variable reads as a race even when the round trip orders it. Var's lock makes the ordering visible.

func (*Var[T]) Load

func (v *Var[T]) Load() T

Load returns the current value.

func (*Var[T]) Store

func (v *Var[T]) Store(value T)

Store replaces the value.

func (*Var[T]) Update

func (v *Var[T]) Update(fn func(T) T) T

Update changes the value in place and returns the result.

Jump to

Keyboard shortcuts

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