mirror of
https://github.com/taigrr/systemctl.git
synced 2026-03-09 00:14:38 -07:00
fix(helpers): return ErrValueNotSet for nonexistent units in GetNumRestarts (#9)
systemd returns NRestarts=0 for units with LoadState=not-found, making it indistinguishable from a genuinely loaded unit with zero restarts. GetNumRestarts now checks LoadState when NRestarts is 0 and returns ErrValueNotSet for units that don't exist, matching GetMemoryUsage behavior. Also adds unit tests for filterErr (all stderr error mapping cases) and HasValidUnitSuffix (all valid unit types + negative cases). Updates syncthing test expectation from ErrValueNotSet to nil since loaded-but-inactive units legitimately have NRestarts=0.
This commit is contained in:
@@ -105,8 +105,8 @@ func TestGetNumRestarts(t *testing.T) {
|
||||
|
||||
// try nonexistant unit in user mode as user
|
||||
{"nonexistant", ErrValueNotSet, Options{UserMode: false}, true},
|
||||
// try existing unit in user mode as user
|
||||
{"syncthing", ErrValueNotSet, Options{UserMode: true}, true},
|
||||
// try existing unit in user mode as user (loaded, so NRestarts=0 is valid)
|
||||
{"syncthing", nil, Options{UserMode: true}, true},
|
||||
// try existing unit in system mode as user
|
||||
{"nginx", nil, Options{UserMode: false}, true},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user