From c7b2246a4643a7370d8667be0aa3f8d134a9a404 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 16 May 2021 22:58:49 -0700 Subject: [PATCH] Finishes IsEnabled test cases --- systemctl_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/systemctl_test.go b/systemctl_test.go index a0072d8..a1b7893 100644 --- a/systemctl_test.go +++ b/systemctl_test.go @@ -189,6 +189,61 @@ func TestIsActive(t *testing.T) { } +func TestIsEnabled(t *testing.T) { + unit := "nginx" + userMode := false + if userString != "root" && userString != "system" { + userMode = true + unit = "syncthing" + } + t.Run(fmt.Sprintf("check enabled"), func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + err := Enable(ctx, unit, Options{UserMode: userMode}) + if err != nil { + t.Errorf("Unable to enable %s: %v", unit, err) + } + isEnabled, err := IsEnabled(ctx, unit, Options{UserMode: userMode}) + if !isEnabled { + t.Errorf("IsEnabled didn't return true for %s", unit) + } + }) + t.Run(fmt.Sprintf("check disabled"), func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + err := Disable(ctx, unit, Options{UserMode: userMode}) + if err != nil { + t.Errorf("Unable to disable %s", unit) + } + isEnabled, err := IsEnabled(ctx, unit, Options{UserMode: userMode}) + if err != nil { + t.Errorf("Error: %v", err) + } + if isEnabled { + t.Errorf("IsEnabled didn't return false for %s", unit) + } + Enable(ctx, unit, Options{UserMode: false}) + }) + t.Run(fmt.Sprintf("check masked"), func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + err := Mask(ctx, unit, Options{UserMode: userMode}) + if err != nil { + t.Errorf("Unable to mask %s", unit) + } + isEnabled, err := IsEnabled(ctx, unit, Options{UserMode: userMode}) + if err != ErrMasked { + t.Errorf("error is %v, but should have been %v", err, ErrMasked) + } + if isEnabled { + t.Errorf("IsEnabled didn't return false for %s", unit) + } + Unmask(ctx, unit, Options{UserMode: false}) + Enable(ctx, unit, Options{UserMode: false}) + }) + +} + // Runs through all defined Properties in parallel and checks for error cases func TestShow(t *testing.T) { if testing.Short() {