@@ -128,6 +128,21 @@ 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 (trTarget .name , "replace" , trTarget .props , []AuxiliaryUnit {{Name : trAux .name , Properties : trAux .props }}, reschan )
134+ if err != nil {
135+ return err
136+ }
137+
138+ job := <- reschan
139+ if job != "done" {
140+ return fmt .Errorf ("Job is not done: %s" , job )
141+ }
142+
143+ return nil
144+ }
145+
131146func runStopUnit (t * testing.T , conn * Conn , trTarget TrUnitProp ) error {
132147 reschan := make (chan string )
133148 _ , err := conn .StopUnit (trTarget .name , "replace" , reschan )
@@ -850,6 +865,11 @@ func TestSetUnitProperties(t *testing.T) {
850865 }
851866}
852867
868+ type TrUnitSocketListenProp struct {
869+ Type string
870+ Address string
871+ }
872+
853873// Ensure that oneshot transient unit starting and stopping works.
854874func TestStartStopTransientUnitAll (t * testing.T ) {
855875 testCases := []struct {
@@ -991,6 +1011,29 @@ func TestStartStopTransientUnitAll(t *testing.T) {
9911011 },
9921012 checkFunc : checkTransientUnitConflicts ,
9931013 },
1014+ {
1015+ trTarget : TrUnitProp {
1016+ name : "testing-aux-unit.socket" ,
1017+ props : []Property {
1018+ {
1019+ Name : "Listen" ,
1020+ Value : dbus .MakeVariant ([]TrUnitSocketListenProp {
1021+ {
1022+ Type : "Stream" ,
1023+ Address : path .Join (os .TempDir (), "go-systemd-test.sock" ),
1024+ },
1025+ }),
1026+ },
1027+ },
1028+ },
1029+ trDep : TrUnitProp {
1030+ name : "testing-aux-unit.service" ,
1031+ props : []Property {
1032+ PropExecStart ([]string {"/bin/sleep" , "400" }, false ),
1033+ },
1034+ },
1035+ checkFunc : checkTransientUnitAux ,
1036+ },
9941037 }
9951038
9961039 for i , tt := range testCases {
@@ -1332,6 +1375,47 @@ func checkTransientUnitConflicts(t *testing.T, trTarget TrUnitProp, trDep TrUnit
13321375 return nil
13331376}
13341377
1378+ func checkTransientUnitAux (t * testing.T , trTarget TrUnitProp , trDep TrUnitProp ) error {
1379+ conn := setupConn (t )
1380+
1381+ // Start the target unit with dep as auxiliary unit
1382+ err := runStartTrUnitWithAux (t , conn , trTarget , trDep )
1383+ if err != nil {
1384+ return err
1385+ }
1386+
1387+ target := getUnitStatusSingle (conn , trTarget .name )
1388+ if target == nil || target .ActiveState != "active" {
1389+ return fmt .Errorf ("Test unit %s not active, should be active" , trTarget .name )
1390+ }
1391+
1392+ aux := getUnitStatusSingle (conn , trDep .name )
1393+ if aux == nil {
1394+ return fmt .Errorf ("Test unit %s not found" , trDep .name )
1395+ }
1396+
1397+ if aux .ActiveState == "active" {
1398+ return fmt .Errorf ("Test unit %s active, should be inactive" , trDep .name )
1399+ }
1400+
1401+ err = runStopUnit (t , conn , trTarget )
1402+ if err != nil {
1403+ return err
1404+ }
1405+
1406+ target = getUnitStatusSingle (conn , trTarget .name )
1407+ if target != nil {
1408+ return fmt .Errorf ("Test unit %s found in list, should be stopped" , trTarget .name )
1409+ }
1410+
1411+ aux = getUnitStatusSingle (conn , trDep .name )
1412+ if aux != nil {
1413+ return fmt .Errorf ("Test unit %s found in list, should be stopped" , trTarget .name )
1414+ }
1415+
1416+ return nil
1417+ }
1418+
13351419func runSleep (t * testing.T ) uint32 {
13361420 cmd := exec .Command ("/bin/sleep" , "400" )
13371421 err := cmd .Start ()
0 commit comments