How to test os.exit?

How can we test the log.fatal() or any function that causes the os.exit() ?

for example if i have a function

func f(){
log.Fatal(“test”)
}

so how can i test it without causing tests to fail.

I’m not sure if it’s possible. It calls a syscall directly https://github.com/golang/go/blob/master/src/os/proc.go#L67. What you can do is wrapping the functions with your own and mocking it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.