diff --git a/systemctl.go b/systemctl.go index 050d42a..3c4d0cd 100644 --- a/systemctl.go +++ b/systemctl.go @@ -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 { diff --git a/systemctl_test.go b/systemctl_test.go index e20dee4..2642e87 100644 --- a/systemctl_test.go +++ b/systemctl_test.go @@ -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) + } +}