check stderr before reporting back error 1

This commit is contained in:
Tai Groot
2021-05-14 16:55:17 -07:00
parent 2517125d98
commit feff1f6edd
5 changed files with 68 additions and 12 deletions

28
systemctl_test.go Normal file
View File

@@ -0,0 +1,28 @@
package systemctl
import (
"context"
"testing"
"time"
)
func TestEnableNonexistant(t *testing.T) {
unit := "nonexistant"
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := Enable(ctx, unit, true)
if err != ErrDoesNotExist {
t.Errorf("error is %v, but should have been %v", err, ErrDoesNotExist)
}
}
func TestEnableNoPermissions(t *testing.T) {
unit := "nginx"
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := Enable(ctx, unit, false)
if err != ErrInsufficientPermissions {
t.Errorf("error is %v, but should have been %v", err, ErrInsufficientPermissions)
}
}