logindtest

package
v0.3.20 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 13 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 logindtest is a fake systemd-logind on a private bus: the manager, the user's sessions on seat0, the calling user, the calls lys makes of them, and the signals logind sends.

Index

Constants

View Source
const (
	Seat     logind.SeatID   = "seat0"
	SeatPath dbus.ObjectPath = logind.ManagerPath + "/seat/seat0"
)

The seat every session of the fake is on.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Method string
	Path   dbus.ObjectPath
	Args   []any
}

Call is one method call the fake answered, refused or not. Method is the interface's last name and the member, such as Manager.Suspend; Path is the object's real path, an alias resolved.

type Config

type Config struct {
	Own     logind.SessionID
	Display logind.SessionID
}

Config is the user the fake serves, seen from the caller. Own is the session every calling process is in, "" for a caller in none (a service of the systemd user manager); Display is the user's display session, "" for none. They may be the same session.

type Event

type Event string

Event is one entry of the fake's timeline.

const (
	EventLock              Event = "lock"
	EventLockedHint        Event = "locked-hint"
	EventUnlockedHint      Event = "unlocked-hint"
	EventInhibit           Event = "inhibit"
	EventInhibitorReleased Event = "inhibitor-released"
	EventSuspend           Event = "suspend"
	EventReboot            Event = "reboot"
	EventPowerOff          Event = "poweroff"
)

The entries Events records, in the order they happen.

type Logind

type Logind struct {
	// Bus is the private bus logind owns its name on.
	Bus *dbustest.Bus
	// Calls lists every method call, in order.
	Calls dbustest.Var[[]Call]
	// Events lists the locks, LockedHint changes, inhibitors taken and
	// released and power actions, in the order they happened.
	Events dbustest.Var[[]Event]
	// Inhibitors counts the inhibitors held now.
	Inhibitors dbustest.Var[int]
	// OnLock runs after a Lock is recorded, as the lock screen answering
	// logind's Lock signal would, on a goroutine of its own; nil does
	// nothing. The fake waits for the hooks still running before its
	// connection closes at the end of the test.
	OnLock dbustest.Var[func()]
	// contains filtered or unexported fields
}

Logind is the fake. Its manager resolves "auto" to Own, else Display, and "self" to Own; the /session/auto and /session/self aliases and /user/self are served likewise. Sessions start active and unlocked.

The methods that have logind announce something (SetLockedHint, SetActive, PrepareForSleep, Lock, Unlock, PauseDevice, ResumeDevice) report a failure with t.Errorf and return false. Unlike t.Fatalf that is allowed on any goroutine of the test, so an OnLock hook may call them.

func Serve

func Serve(t testing.TB, bus *dbustest.Bus, cfg Config) *Logind

Serve runs the fake for cfg on bus, which the test shares with other services, on a connection of its own.

func Start

func Start(t testing.TB, cfg Config) *Logind

Start runs the fake for cfg on a private bus of its own.

func StartUnit

func StartUnit(t testing.TB, cfg Config) *Logind

StartUnit runs the fake as the system bus of a process the systemd user manager started: XDG_SESSION_ID unset for the test, and every D-Bus client the test runs dialling the fake for the system bus.

func (*Logind) AnnounceProperty

func (l *Logind) AnnounceProperty(t testing.TB, id logind.SessionID, name string, v any) bool

AnnounceProperty has logind announce, with PropertiesChanged, that property name of session id changed to v, whatever v is and without changing the session: a LockedHint that is no boolean is what a reader must report rather than take for a hint.

func (*Logind) CallsTo

func (l *Logind) CallsTo(method string) []Call

CallsTo lists the calls of method, in order.

func (*Logind) Lock

func (l *Logind) Lock(t testing.TB, id logind.SessionID) bool

Lock emits session id's Lock signal, as `loginctl lock-session` has logind do.

func (*Logind) Methods

func (l *Logind) Methods() []string

Methods lists the methods called, in order.

func (*Logind) PauseDevice

func (l *Logind) PauseDevice(t testing.TB, id logind.SessionID, d logind.Device, kind logind.PauseKind) bool

PauseDevice emits session id's PauseDevice for d.

func (*Logind) PrepareForSleep

func (l *Logind) PrepareForSleep(t testing.TB, start bool) bool

PrepareForSleep emits the manager's PrepareForSleep(start), as logind does around a sleep someone else asked for.

func (*Logind) Refuse

func (l *Logind) Refuse(method string, err *dbus.Error)

Refuse makes every later call of method (such as Manager.Suspend) fail with err; nil answers it again.

func (*Logind) ResumeDevice

func (l *Logind) ResumeDevice(t testing.TB, id logind.SessionID, d logind.Device) bool

ResumeDevice emits session id's ResumeDevice for d, carrying a descriptor of /dev/null.

func (*Logind) SetActive

func (l *Logind) SetActive(t testing.TB, id logind.SessionID, active bool) bool

SetActive changes whether session id is in the foreground and announces it with PropertiesChanged, as logind does on a VT switch.

func (*Logind) SetLockedHint

func (l *Logind) SetLockedHint(t testing.TB, id logind.SessionID, locked bool) bool

SetLockedHint changes session id's LockedHint and announces it with PropertiesChanged, as logind does when the lock screen sets it.

func (*Logind) Unlock

func (l *Logind) Unlock(t testing.TB, id logind.SessionID) bool

Unlock emits session id's Unlock signal, as `loginctl unlock-session` has logind do.

Jump to

Keyboard shortcuts

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