Test disable function
This commit is contained in:
parent
b1346b7992
commit
184bbc4936
@ -15,8 +15,8 @@ In fact, if `systemctl` isn't found in the `PATH`, this library will panic.
|
|||||||
## Supported systemctl functions
|
## Supported systemctl functions
|
||||||
|
|
||||||
- [ ] `systemctl daemon-reload`
|
- [ ] `systemctl daemon-reload`
|
||||||
- [ ] `systemctl disable`
|
- [x] `systemctl disable`
|
||||||
- [ ] `systemctl enable`
|
- [x] `systemctl enable`
|
||||||
- [ ] `systemctl is-active`
|
- [ ] `systemctl is-active`
|
||||||
- [ ] `systemctl is-enabled`
|
- [ ] `systemctl is-enabled`
|
||||||
- [ ] `systemctl is-failed`
|
- [ ] `systemctl is-failed`
|
||||||
|
@ -78,6 +78,51 @@ func TestEnable(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDisable(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
unit string
|
||||||
|
err error
|
||||||
|
opts Options
|
||||||
|
runAsUser bool
|
||||||
|
}{
|
||||||
|
// Run these tests only as a user
|
||||||
|
|
||||||
|
//try nonexistant unit in user mode as user
|
||||||
|
{"nonexistant", ErrDoesNotExist, Options{usermode: true}, true},
|
||||||
|
// try existing unit in user mode as user
|
||||||
|
{"syncthing", nil, Options{usermode: true}, true},
|
||||||
|
// try nonexisting unit in system mode as user
|
||||||
|
{"nonexistant", ErrInsufficientPermissions, Options{usermode: false}, true},
|
||||||
|
// try existing unit in system mode as user
|
||||||
|
{"nginx", ErrInsufficientPermissions, Options{usermode: false}, true},
|
||||||
|
|
||||||
|
// Run these tests only as a superuser
|
||||||
|
|
||||||
|
// try nonexistant unit in system mode as system
|
||||||
|
{"nonexistant", ErrDoesNotExist, Options{usermode: false}, false},
|
||||||
|
// try existing unit in system mode as system
|
||||||
|
{"nginx", ErrBusFailure, Options{usermode: true}, false},
|
||||||
|
// try existing unit in system mode as system
|
||||||
|
{"nginx", nil, Options{usermode: false}, false},
|
||||||
|
}
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(fmt.Sprintf("%s as %s", tc.unit, userString), func(t *testing.T) {
|
||||||
|
if (userString == "root" || userString == "system") && tc.runAsUser {
|
||||||
|
t.Skip("skipping user test while running as superuser")
|
||||||
|
} else if (userString != "root" && userString != "system") && !tc.runAsUser {
|
||||||
|
t.Skip("skipping superuser test while running as user")
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
err := Disable(ctx, tc.unit, tc.opts)
|
||||||
|
if err != tc.err {
|
||||||
|
t.Errorf("error is %v, but should have been %v", err, tc.err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Runs through all defined properties and checks for error cases
|
// Runs through all defined properties and checks for error cases
|
||||||
func TestShow(t *testing.T) {
|
func TestShow(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user