//go:build linux
package children
import (
"os/exec"
"testing"
)
// A command that is not a zit child still starts in the work group
// once there is one, and runs as before when there is none.
func TestConfineUsesTheWorkGroup(t *testing.T) {
was := workGroup.Load()
t.Cleanup(func() { workGroup.Store(was) })
workGroup.Store(-1)
none := exec.Command("git", "fetch")
Confine(none)
if none.SysProcAttr != nil && none.SysProcAttr.UseCgroupFD {
t.Errorf("FAIL: with no group the command was bound to fd %d", none.SysProcAttr.CgroupFD)
}
workGroup.Store(42)
cmd := exec.Command("git", "fetch")
Confine(cmd)
if cmd.SysProcAttr == nil || !cmd.SysProcAttr.UseCgroupFD || cmd.SysProcAttr.CgroupFD != 42 {
t.Errorf("FAIL: the command was not bound to the work group: %+v", cmd.SysProcAttr)
}
}