Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
go-version: stable
- uses: golangci/golangci-lint-action@v9
with:
version: v2.3
version: v2.7

all-done:
needs:
Expand Down
8 changes: 0 additions & 8 deletions dbus/dbus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,3 @@ func TestPathBusUnescape(t *testing.T) {
}
}
}

// TestNew ensures that New() works without errors.
func TestNew(t *testing.T) {
_, err := New()
if err != nil {
t.Fatal(err)
}
}
38 changes: 4 additions & 34 deletions dbus/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ type TrUnitProp struct {
}

func setupConn(t *testing.T) *Conn {
// TODO: change to NewWithContext(t.Context()) once we switch to go1.24.
conn, err := New()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
conn.Close()
})

return conn
}
Expand Down Expand Up @@ -154,7 +158,6 @@ func isJobStatusEmpty(job JobStatus) bool {
func TestStartStopUnit(t *testing.T) {
target := "start-stop.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
linkUnit(target, conn, t)
Expand Down Expand Up @@ -209,7 +212,6 @@ func TestStartStopUnit(t *testing.T) {
func TestRestartUnit(t *testing.T) {
target := "start-stop.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
linkUnit(target, conn, t)
Expand Down Expand Up @@ -295,7 +297,6 @@ func TestRestartUnit(t *testing.T) {
func TestReloadUnit(t *testing.T) {
target := "reload.service"
conn := setupConn(t)
defer conn.Close()

err := conn.Subscribe()
if err != nil {
Expand Down Expand Up @@ -380,7 +381,6 @@ waitevent:
func TestReloadOrRestartUnit(t *testing.T) {
target := "reload.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
linkUnit(target, conn, t)
Expand Down Expand Up @@ -457,7 +457,6 @@ func TestReloadOrRestartUnit(t *testing.T) {
// Ensure that GetUnitByPID works.
func TestGetUnitByPID(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

path, err := conn.GetUnitByPID(context.Background(), 1)
if err != nil {
Expand All @@ -472,7 +471,6 @@ func TestGetUnitByPID(t *testing.T) {
// Ensure that GetUnitNameByPID works.
func TestGetUnitNameByPID(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

name, err := conn.GetUnitNameByPID(context.Background(), 1)
if err != nil {
Expand All @@ -490,7 +488,6 @@ func TestListUnitsByNames(t *testing.T) {
target2 := "unexisting.service"

conn := setupConn(t)
defer conn.Close()

units, err := conn.ListUnitsByNames([]string{target1, target2})
if err != nil {
Expand Down Expand Up @@ -520,7 +517,6 @@ func TestListUnitsByPatterns(t *testing.T) {
target2 := "unexisting.service"

conn := setupConn(t)
defer conn.Close()

units, err := conn.ListUnitsByPatterns([]string{}, []string{"systemd-journald*", target2})
if err != nil {
Expand All @@ -547,7 +543,6 @@ func TestListUnitsFiltered(t *testing.T) {
target := "systemd-journald.service"

conn := setupConn(t)
defer conn.Close()

units, err := conn.ListUnitsFiltered([]string{"active"})
if err != nil {
Expand Down Expand Up @@ -580,7 +575,6 @@ func TestListUnitFilesByPatterns(t *testing.T) {
target2 := "exit.target"

conn := setupConn(t)
defer conn.Close()

units, err := conn.ListUnitFilesByPatterns([]string{"static"}, []string{"systemd-journald*", target2})
if err != nil {
Expand Down Expand Up @@ -614,7 +608,6 @@ func TestListUnitFiles(t *testing.T) {
target2 := "exit.target"

conn := setupConn(t)
defer conn.Close()

units, err := conn.ListUnitFiles()
if err != nil {
Expand Down Expand Up @@ -642,7 +635,6 @@ func TestListUnitFiles(t *testing.T) {
func TestEnableDisableUnit(t *testing.T) {
target := "enable-disable.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
abs := findFixture(target, t)
Expand Down Expand Up @@ -734,7 +726,6 @@ func TestListJobs(t *testing.T) {
// TestSystemState tests if system state is one of the valid states
func TestSystemState(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

prop, err := conn.SystemState()
if err != nil {
Expand Down Expand Up @@ -767,7 +758,6 @@ func TestSystemState(t *testing.T) {
// systems and ensures that one of its properties is valid.
func TestGetUnitProperties(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

unit := "-.mount"

Expand Down Expand Up @@ -798,7 +788,6 @@ func TestGetUnitProperties(t *testing.T) {
// as a fail will manifest as GetUnitProperties hanging indefinitely.
func TestGetUnitPropertiesRejectsInvalidName(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

unit := "//invalid#$^/"

Expand All @@ -817,7 +806,6 @@ func TestGetUnitPropertiesRejectsInvalidName(t *testing.T) {
// on all systemd systems and ensures that one of its property is valid.
func TestGetServiceProperty(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

service := "systemd-udevd.service"

Expand All @@ -840,7 +828,6 @@ func TestGetServiceProperty(t *testing.T) {
// property was set.
func TestSetUnitProperties(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

const (
unit = "-.mount"
Expand Down Expand Up @@ -1016,7 +1003,6 @@ func TestStartStopTransientUnitAll(t *testing.T) {
// Ensure that basic transient unit starting and stopping works.
func checkTransientUnit(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the unit
err := runStartTrUnit(t, conn, trTarget)
Expand Down Expand Up @@ -1047,7 +1033,6 @@ func checkTransientUnit(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) err

func checkTransientUnitOneshot(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the unit
err := runStartTrUnit(t, conn, trTarget)
Expand Down Expand Up @@ -1079,7 +1064,6 @@ func checkTransientUnitOneshot(t *testing.T, trTarget TrUnitProp, trDep TrUnitPr
// Ensure that transient unit with Requires starting and stopping works.
func checkTransientUnitRequires(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the dependent unit
err := runStartTrUnit(t, conn, trDep)
Expand Down Expand Up @@ -1128,7 +1112,6 @@ func checkTransientUnitRequires(t *testing.T, trTarget TrUnitProp, trDep TrUnitP
// Ensure that transient unit with RequiresOverridable starting and stopping works.
func checkTransientUnitRequiresOv(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the dependent unit
err := runStartTrUnit(t, conn, trDep)
Expand Down Expand Up @@ -1178,7 +1161,6 @@ func checkTransientUnitRequiresOv(t *testing.T, trTarget TrUnitProp, trDep TrUni
// It's expected for target unit to fail, as its child is not started at all.
func checkTransientUnitRequisite(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the target unit
err := runStartTrUnit(t, conn, trTarget)
Expand All @@ -1198,7 +1180,6 @@ func checkTransientUnitRequisite(t *testing.T, trTarget TrUnitProp, trDep TrUnit
// It's expected for target unit to fail, as its child is not started at all.
func checkTransientUnitRequisiteOv(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the target unit
err := runStartTrUnit(t, conn, trTarget)
Expand All @@ -1218,7 +1199,6 @@ func checkTransientUnitRequisiteOv(t *testing.T, trTarget TrUnitProp, trDep TrUn
// It's expected for target to successfully start, even when its child is not started.
func checkTransientUnitWants(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the target unit
err := runStartTrUnit(t, conn, trTarget)
Expand Down Expand Up @@ -1251,7 +1231,6 @@ func checkTransientUnitWants(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp
// Stopping its child should result in stopping target unit.
func checkTransientUnitBindsTo(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the dependent unit
err := runStartTrUnit(t, conn, trDep)
Expand Down Expand Up @@ -1295,7 +1274,6 @@ func checkTransientUnitBindsTo(t *testing.T, trTarget TrUnitProp, trDep TrUnitPr
// Ensure that transient unit with Conflicts starting and stopping works.
func checkTransientUnitConflicts(t *testing.T, trTarget TrUnitProp, trDep TrUnitProp) error {
conn := setupConn(t)
defer conn.Close()

// Start the dependent unit
err := runStartTrUnit(t, conn, trDep)
Expand Down Expand Up @@ -1375,7 +1353,6 @@ func runSleep(t *testing.T) uint32 {
// Ensure that putting running programs into scopes works
func TestStartStopTransientScope(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

pid := runSleep(t)
props := []Property{
Expand Down Expand Up @@ -1418,7 +1395,6 @@ func TestStartStopTransientScope(t *testing.T) {
func TestKillUnit(t *testing.T) {
target := "start-stop.service"
conn := setupConn(t)
defer conn.Close()

err := conn.Subscribe()
if err != nil {
Expand Down Expand Up @@ -1481,7 +1457,6 @@ waitevent:
func TestResetFailedUnit(t *testing.T) {
target := "start-failed.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
linkUnit(target, conn, t)
Expand Down Expand Up @@ -1535,7 +1510,6 @@ func TestResetFailedUnit(t *testing.T) {
func TestConnJobListener(t *testing.T) {
target := "start-stop.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
linkUnit(target, conn, t)
Expand Down Expand Up @@ -1567,7 +1541,6 @@ func TestConnJobListener(t *testing.T) {
func TestMaskUnmask(t *testing.T) {
target := "mask-unmask.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
abs := findFixture(target, t)
Expand Down Expand Up @@ -1619,7 +1592,6 @@ func TestMaskUnmask(t *testing.T) {
// Test a global Reload
func TestReload(t *testing.T) {
conn := setupConn(t)
defer conn.Close()

err := conn.Reload()
if err != nil {
Expand Down Expand Up @@ -1647,7 +1619,6 @@ func TestUnitName(t *testing.T) {
func TestFreezer(t *testing.T) {
target := "freeze.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
linkUnit(target, conn, t)
Expand Down Expand Up @@ -1705,7 +1676,6 @@ func TestFreezer(t *testing.T) {
func testAttachProcessesToUnit(t *testing.T, subcgroup string) {
target := "attach-processes.service"
conn := setupConn(t)
defer conn.Close()

setupUnit(target, conn, t)
linkUnit(target, conn, t)
Expand Down
7 changes: 2 additions & 5 deletions dbus/subscription_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ import (
func TestSubscriptionSetUnit(t *testing.T) {
target := "subscribe-events-set.service"

conn, err := New()
if err != nil {
t.Fatal(err)
}
conn := setupConn(t)

err = conn.Subscribe()
err := conn.Subscribe()
if err != nil {
t.Fatal(err)
}
Expand Down
30 changes: 8 additions & 22 deletions dbus/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ import (

// TestSubscribe exercises the basics of subscription
func TestSubscribe(t *testing.T) {
conn, err := New()
if err != nil {
t.Fatal(err)
}
conn := setupConn(t)

err = conn.Subscribe()
err := conn.Subscribe()
if err != nil {
t.Fatal(err)
}
Expand All @@ -41,12 +38,9 @@ func TestSubscribe(t *testing.T) {
func TestSubscribeUnit(t *testing.T) {
target := "subscribe-events.service"

conn, err := New()
if err != nil {
t.Fatal(err)
}
conn := setupConn(t)

err = conn.Subscribe()
err := conn.Subscribe()
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -100,11 +94,7 @@ success:
func TestSubStateSubscription(t *testing.T) {
target := "subscribe-events.service"

conn, err := New()
if err != nil {
t.Fatal(err)
}
defer conn.Close()
conn := setupConn(t)

updateCh := make(chan *SubStateUpdate, 256)
errCh := make(chan error, 256)
Expand All @@ -114,7 +104,7 @@ func TestSubStateSubscription(t *testing.T) {
linkUnit(target, conn, t)

reschan := make(chan string)
_, err = conn.StartUnit(target, "replace", reschan)
_, err := conn.StartUnit(target, "replace", reschan)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -142,13 +132,9 @@ func TestSubStateSubscription(t *testing.T) {
func TestPropertiesSubscription(t *testing.T) {
target := "subscribe-events.service"

conn, err := New()
if err != nil {
t.Fatal(err)
}
defer conn.Close()
conn := setupConn(t)

err = conn.Subscribe()
err := conn.Subscribe()
if err != nil {
t.Fatal(err)
}
Expand Down