-1

I am using Monkey Patching in Go. When I debug the following code in VSCode it shows that the function proc.Signal return the error programmed.

func TestCheckProcessRunning(t *testing.T) {
    monkey.Patch((*os.Process).Signal, func(p *os.Process, sig os.Signal) error {
        return errors.New("Signal failed")
    })
    proc := &os.Process{}
    sig_e := proc.Signal(syscall.Signal(0))
    fmt.Printf("%s\n", sig_e)

}
Signal failed

But when I tried to run the test using go test . , the patch is no longer applied and got a different error:

os: process not initialized 

Any idea of what I am doing wrong?

1 Answers1

-1

It seems it needed the flag -gcflags=-l

go test -gcflags=-l .