Skip to content
quarry Artifact [d6f7dcecb3]
Login

Artifact [d6f7dcecb3]

Artifact d6f7dcecb32f4502ec4f53e78d34e573059a257cfe271228a456e7e7af2e1951:


//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)
	}
}