What am I trying to do?
-> Run a unit test which scans running processes and can extract value from the process list by "scanning" (looking into cmd lines by name) for the proc name (sh)
What is not working?
-> The code below seems to be flaky, especially on Mac (tests need to run on Mac and linux). Haven't identified why yet
What did I try?
-> Spin up a background process with sh and custom extra args (sh shouldn't crash) which sleeps so that I have time to look into the process list during the test and extract the value.
Code so far:
s := []string{"-c", `sleep 20; -` + arg + ` ` + value}
cmd := exec.Command("sh", s...)
err := cmd.Start()
go func() {
res := checkProcs("sh", arg)
//kill cmd and test verification
}
I am happy to give up the sh approach, I just need something which "survives" the go routine and can be scanned for value. I was also thinking about some custom compile but couldn't find how to compile something on the file during a test.