-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Ability to reliably test overseer #12
Comments
Sorry Rafael, swamped with work, though you raise a good point - this package should have proper tests. No time now, though will leave open so it's not forgotten :) |
Thanks @jpillora! I'm now thinking that testing a server with a non-stop feature isn't so trivial. After the sub-process exits, the overseer framework will try to restart it or will execute the proc_master.go (fork) mp.debugf("prog exited with %d", code)
//if a restarts are disabled or if it was an
//unexpected creash, proxy this exit straight
//through to the main process
if mp.NoRestart || !mp.restarting {
os.Exit(code)
} We could have a test flag in the configuration, as we have for the debug mode, that could avoid calling |
The test mode flag allows to unit test the server, disabling the fork and the service restart mechanisms. Resolves jpillora#12
With this PR the test is now easier: program.gopackage main
import (
"time"
"github.com/rafaeljusto/overseer"
"github.com/rafaeljusto/overseer/fetcher"
)
var value = ""
func main() {
overseer.Run(overseer.Config{
Program: prog,
Address: ":3000",
Fetcher: &fetcher.HTTP{
URL: "http://localhost:4000/binaries/myapp",
Interval: 1 * time.Second,
},
Test: true,
})
}
func prog(state overseer.State) {
println("Running program")
value = "2"
} program_test.gopackage main
import "testing"
func Test_main(t *testing.T) {
main()
if value != "2" {
t.Errorf("expected value 2, got %s", value)
}
} |
I was trying to create some unit tests to my app that is using overseer. The test need to change the
os.Args
so it can test different scenarios. The problem is that overseer starts a new sub-process (as it should) and the Go test framework fails to parse the modified arguments, as it doesn't recognize them. Check the following simplified example:program.go
program_test.go
output
One solution would be instead of modifying the
os.Args
, set an environment variable and detect it inside the sub-process execution:program_test.go
output
Is there any better solution for this situation? If not, this issue can be closed and could be used in the future for others that have the same problem that I had.
The text was updated successfully, but these errors were encountered: