@@ -128,6 +128,28 @@ func runStartTrUnit(t *testing.T, conn *Conn, trTarget TrUnitProp) error {
128128 return nil
129129}
130130
131+ func runStartTrUnitWithAux (t * testing.T , conn * Conn , trTarget TrUnitProp , trAux TrUnitProp ) error {
132+ reschan := make (chan string )
133+ _ , err := conn .StartTransientUnitAux (
134+ context .TODO (), // Switch to t.Context once go < 1.24 is not supported.
135+ trTarget .name ,
136+ "replace" ,
137+ trTarget .props ,
138+ []PropertyCollection {{Name : trAux .name , Properties : trAux .props }},
139+ reschan ,
140+ )
141+ if err != nil {
142+ return err
143+ }
144+
145+ job := <- reschan
146+ if job != "done" {
147+ return fmt .Errorf ("Job is not done: %s" , job )
148+ }
149+
150+ return nil
151+ }
152+
131153func runStopUnit (t * testing.T , conn * Conn , trTarget TrUnitProp ) error {
132154 reschan := make (chan string )
133155 _ , err := conn .StopUnit (trTarget .name , "replace" , reschan )
@@ -850,6 +872,11 @@ func TestSetUnitProperties(t *testing.T) {
850872 }
851873}
852874
875+ type TrUnitSocketListenProp struct {
876+ Type string
877+ Address string
878+ }
879+
853880// Ensure that oneshot transient unit starting and stopping works.
854881func TestStartStopTransientUnitAll (t * testing.T ) {
855882 testCases := []struct {
@@ -991,6 +1018,29 @@ func TestStartStopTransientUnitAll(t *testing.T) {
9911018 },
9921019 checkFunc : checkTransientUnitConflicts ,
9931020 },
1021+ {
1022+ trTarget : TrUnitProp {
1023+ name : "testing-aux-unit.socket" ,
1024+ props : []Property {
1025+ {
1026+ Name : "Listen" ,
1027+ Value : dbus .MakeVariant ([]TrUnitSocketListenProp {
1028+ {
1029+ Type : "Stream" ,
1030+ Address : path .Join (t .TempDir (), "go-systemd-test.sock" ),
1031+ },
1032+ }),
1033+ },
1034+ },
1035+ },
1036+ trDep : TrUnitProp {
1037+ name : "testing-aux-unit.service" ,
1038+ props : []Property {
1039+ PropExecStart ([]string {"/bin/sleep" , "400" }, false ),
1040+ },
1041+ },
1042+ checkFunc : checkTransientUnitAux ,
1043+ },
9941044 }
9951045
9961046 for i , tt := range testCases {
@@ -1332,6 +1382,47 @@ func checkTransientUnitConflicts(t *testing.T, trTarget TrUnitProp, trDep TrUnit
13321382 return nil
13331383}
13341384
1385+ func checkTransientUnitAux (t * testing.T , trTarget TrUnitProp , trDep TrUnitProp ) error {
1386+ conn := setupConn (t )
1387+
1388+ // Start the target unit with dep as auxiliary unit
1389+ err := runStartTrUnitWithAux (t , conn , trTarget , trDep )
1390+ if err != nil {
1391+ return err
1392+ }
1393+
1394+ target := getUnitStatusSingle (conn , trTarget .name )
1395+ if target == nil || target .ActiveState != "active" {
1396+ return fmt .Errorf ("Test unit %s not active, should be active" , trTarget .name )
1397+ }
1398+
1399+ aux := getUnitStatusSingle (conn , trDep .name )
1400+ if aux == nil {
1401+ return fmt .Errorf ("Test unit %s not found" , trDep .name )
1402+ }
1403+
1404+ if aux .ActiveState == "active" {
1405+ return fmt .Errorf ("Test unit %s active, should be inactive" , trDep .name )
1406+ }
1407+
1408+ err = runStopUnit (t , conn , trTarget )
1409+ if err != nil {
1410+ return err
1411+ }
1412+
1413+ target = getUnitStatusSingle (conn , trTarget .name )
1414+ if target != nil {
1415+ return fmt .Errorf ("Test unit %s found in list, should be stopped" , trTarget .name )
1416+ }
1417+
1418+ aux = getUnitStatusSingle (conn , trDep .name )
1419+ if aux != nil {
1420+ return fmt .Errorf ("Test unit %s found in list, should be stopped" , trTarget .name )
1421+ }
1422+
1423+ return nil
1424+ }
1425+
13351426func runSleep (t * testing.T ) uint32 {
13361427 cmd := exec .Command ("/bin/sleep" , "400" )
13371428 err := cmd .Start ()
0 commit comments