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
- type Call
- type Config
- type Event
- type Logind
- func (l *Logind) AnnounceProperty(t testing.TB, id logind.SessionID, name string, v any) bool
- func (l *Logind) CallsTo(method string) []Call
- func (l *Logind) Lock(t testing.TB, id logind.SessionID) bool
- func (l *Logind) Methods() []string
- func (l *Logind) PauseDevice(t testing.TB, id logind.SessionID, d logind.Device, kind logind.PauseKind) bool
- func (l *Logind) PrepareForSleep(t testing.TB, start bool) bool
- func (l *Logind) Refuse(method string, err *dbus.Error)
- func (l *Logind) ResumeDevice(t testing.TB, id logind.SessionID, d logind.Device) bool
- func (l *Logind) SetActive(t testing.TB, id logind.SessionID, active bool) bool
- func (l *Logind) SetLockedHint(t testing.TB, id logind.SessionID, locked bool) bool
- func (l *Logind) Unlock(t testing.TB, id logind.SessionID) bool
Constants ¶
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 ¶
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 ¶
Serve runs the fake for cfg on bus, which the test shares with other services, on a connection of its own.
func StartUnit ¶
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 ¶
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) Lock ¶
Lock emits session id's Lock signal, as `loginctl lock-session` has logind do.
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 ¶
PrepareForSleep emits the manager's PrepareForSleep(start), as logind does around a sleep someone else asked for.
func (*Logind) Refuse ¶
Refuse makes every later call of method (such as Manager.Suspend) fail with err; nil answers it again.
func (*Logind) ResumeDevice ¶
ResumeDevice emits session id's ResumeDevice for d, carrying a descriptor of /dev/null.
func (*Logind) SetActive ¶
SetActive changes whether session id is in the foreground and announces it with PropertiesChanged, as logind does on a VT switch.
func (*Logind) SetLockedHint ¶
SetLockedHint changes session id's LockedHint and announces it with PropertiesChanged, as logind does when the lock screen sets it.