gofumpt against remaining go files

This commit is contained in:
Tai Groot
2022-10-23 23:28:14 -07:00
parent 33828cf7b9
commit 5da4924315
4 changed files with 8 additions and 13 deletions

View File

@@ -36,5 +36,5 @@ var (
// Something in the stderr output contains the word `Failed`, but it is not a known case // Something in the stderr output contains the word `Failed`, but it is not a known case
// This is a catch-all, and if it's ever seen in the wild, please submit a PR // This is a catch-all, and if it's ever seen in the wild, please submit a PR
ErrUnspecified = errors.New("Unknown error, please submit an issue at github.com/taigrr/systemctl") ErrUnspecified = errors.New("unknown error, please submit an issue at github.com/taigrr/systemctl")
) )

View File

@@ -25,7 +25,7 @@ func TestErrorFuncs(t *testing.T) {
}{ }{
/* Run these tests only as an unpriviledged user */ /* Run these tests only as an unpriviledged user */
//try nonexistant unit in user mode as user // try nonexistant unit in user mode as user
{"nonexistant", ErrDoesNotExist, Options{UserMode: true}, true}, {"nonexistant", ErrDoesNotExist, Options{UserMode: true}, true},
// try existing unit in user mode as user // try existing unit in user mode as user
{"syncthing", nil, Options{UserMode: true}, true}, {"syncthing", nil, Options{UserMode: true}, true},
@@ -53,7 +53,6 @@ func TestErrorFuncs(t *testing.T) {
fName := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name() fName := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
fName = strings.TrimPrefix(fName, "github.com/taigrr/") fName = strings.TrimPrefix(fName, "github.com/taigrr/")
t.Run(fmt.Sprintf("Errorcheck %s", fName), func(t *testing.T) { t.Run(fmt.Sprintf("Errorcheck %s", fName), func(t *testing.T) {
for _, tc := range errCases { for _, tc := range errCases {
t.Run(fmt.Sprintf("%s as %s", tc.unit, userString), func(t *testing.T) { t.Run(fmt.Sprintf("%s as %s", tc.unit, userString), func(t *testing.T) {
if (userString == "root" || userString == "system") && tc.runAsUser { if (userString == "root" || userString == "system") && tc.runAsUser {

View File

@@ -13,7 +13,6 @@ const dateFormat = "Mon 2006-01-02 15:04:05 MST"
// Get start time of a service (`systemctl show [unit] --property ExecMainStartTimestamp`) as a `Time` type // Get start time of a service (`systemctl show [unit] --property ExecMainStartTimestamp`) as a `Time` type
func GetStartTime(ctx context.Context, unit string, opts Options) (time.Time, error) { func GetStartTime(ctx context.Context, unit string, opts Options) (time.Time, error) {
value, err := Show(ctx, unit, properties.ExecMainStartTimestamp, opts) value, err := Show(ctx, unit, properties.ExecMainStartTimestamp, opts)
if err != nil { if err != nil {
return time.Time{}, err return time.Time{}, err
} }

View File

@@ -27,7 +27,7 @@ func TestGetStartTime(t *testing.T) {
runAsUser bool runAsUser bool
}{ }{
// Run these tests only as a user // Run these tests only as a user
//try nonexistant unit in user mode as user // try nonexistant unit in user mode as user
{"nonexistant", ErrUnitNotActive, Options{UserMode: false}, true}, {"nonexistant", ErrUnitNotActive, Options{UserMode: false}, true},
// try existing unit in user mode as user // try existing unit in user mode as user
{"syncthing", ErrUnitNotActive, Options{UserMode: true}, true}, {"syncthing", ErrUnitNotActive, Options{UserMode: true}, true},
@@ -90,8 +90,8 @@ func TestGetStartTime(t *testing.T) {
t.Errorf("Expected start diff to be positive, but got: %d", int(diff)) t.Errorf("Expected start diff to be positive, but got: %d", int(diff))
} }
}) })
} }
func TestGetNumRestarts(t *testing.T) { func TestGetNumRestarts(t *testing.T) {
testCases := []struct { testCases := []struct {
unit string unit string
@@ -101,7 +101,7 @@ func TestGetNumRestarts(t *testing.T) {
}{ }{
// Run these tests only as a user // Run these tests only as a user
//try nonexistant unit in user mode as user // try nonexistant unit in user mode as user
{"nonexistant", ErrValueNotSet, Options{UserMode: false}, true}, {"nonexistant", ErrValueNotSet, Options{UserMode: false}, true},
// try existing unit in user mode as user // try existing unit in user mode as user
{"syncthing", ErrValueNotSet, Options{UserMode: true}, true}, {"syncthing", ErrValueNotSet, Options{UserMode: true}, true},
@@ -170,7 +170,6 @@ func TestGetNumRestarts(t *testing.T) {
t.Errorf("Expected restart count to differ by one, but difference was: %d", secondRestarts-restarts) t.Errorf("Expected restart count to differ by one, but difference was: %d", secondRestarts-restarts)
} }
}) })
} }
func TestGetMemoryUsage(t *testing.T) { func TestGetMemoryUsage(t *testing.T) {
@@ -182,7 +181,7 @@ func TestGetMemoryUsage(t *testing.T) {
}{ }{
// Run these tests only as a user // Run these tests only as a user
//try nonexistant unit in user mode as user // try nonexistant unit in user mode as user
{"nonexistant", ErrValueNotSet, Options{UserMode: false}, true}, {"nonexistant", ErrValueNotSet, Options{UserMode: false}, true},
// try existing unit in user mode as user // try existing unit in user mode as user
{"syncthing", ErrValueNotSet, Options{UserMode: true}, true}, {"syncthing", ErrValueNotSet, Options{UserMode: true}, true},
@@ -230,8 +229,8 @@ func TestGetMemoryUsage(t *testing.T) {
t.Errorf("Expected memory usage between nginx and user.slice to differ, but both were: %d", bytes) t.Errorf("Expected memory usage between nginx and user.slice to differ, but both were: %d", bytes)
} }
}) })
} }
func TestGetPID(t *testing.T) { func TestGetPID(t *testing.T) {
testCases := []struct { testCases := []struct {
unit string unit string
@@ -241,7 +240,7 @@ func TestGetPID(t *testing.T) {
}{ }{
// Run these tests only as a user // Run these tests only as a user
//try nonexistant unit in user mode as user // try nonexistant unit in user mode as user
{"nonexistant", nil, Options{UserMode: false}, true}, {"nonexistant", nil, Options{UserMode: false}, true},
// try existing unit in user mode as user // try existing unit in user mode as user
{"syncthing", nil, Options{UserMode: true}, true}, {"syncthing", nil, Options{UserMode: true}, true},
@@ -296,7 +295,5 @@ func TestGetPID(t *testing.T) {
if pid == secondPid { if pid == secondPid {
t.Errorf("Expected pid != secondPid, but both were: %d", pid) t.Errorf("Expected pid != secondPid, but both were: %d", pid)
} }
}) })
} }