add success case to tests

This commit is contained in:
Tai Groot 2021-05-14 18:01:19 -07:00
parent feff1f6edd
commit 7bedb452e4
Signed by: taigrr
GPG Key ID: D00C269A87614812
2 changed files with 16 additions and 2 deletions

View File

@ -36,7 +36,6 @@ func Stop(ctx context.Context, unit string, usermode bool) error {
return nil
}
// TODO
func Enable(ctx context.Context, unit string, usermode bool) error {
var args = []string{"enable", "--system", unit}
if usermode {
@ -56,7 +55,6 @@ func Enable(ctx context.Context, unit string, usermode bool) error {
return nil
}
// TODO
func Disable(ctx context.Context, unit string, usermode bool) error {
var args = []string{"disable", "--system", unit}
if usermode {

View File

@ -16,6 +16,9 @@ func TestEnableNonexistant(t *testing.T) {
}
}
// Note: test assumes your user isn't root and doesn't have a PolKit rule allowing access
// to configure nginx. Whether it's installed should be irrelevant.
func TestEnableNoPermissions(t *testing.T) {
unit := "nginx"
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
@ -26,3 +29,16 @@ func TestEnableNoPermissions(t *testing.T) {
}
}
// Note: requires the syncthing unit to be available on the tester's system.
// this is just what was available on mine, should you want to change it,
// either to something in this repo or more common, feel free to submit a PR.
func TestEnableSuccess(t *testing.T) {
unit := "syncthing"
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := Enable(ctx, unit, true)
if err != nil {
t.Errorf("error is %v, but should have been %v", err, nil)
}
}