Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I like a lot of what they've done here. My testing looks a bit different however.

srv, err := newTestServer()

require.NoError(t, err)

defer srv.Close()

resp, err := http.Post(fmt.Sprintf("http://localhost:%d/signup/json", srv.Port()), "application/json", strings.NewReader(` {"email":"test@example.com", "password": "p@55Word", "password_copy": "p@55Word"} `))

In my newTestServer, I spin up a server with fakes for my dependencies. If I want to test a dependency error, I replace that property with a fake that will return an error. I can validate my error paths. I can validate my log entries. I can validate my metric emission. I can validate timeouts and graceful shutdowns.

After the server starts, I inspect to determine which port it is running on (default is :0 so I have to wait to see what it got bound to).

My "unit" tests can test at the handler level or the http level, making sure that I can fully test the code as the users of my system will see it, exercising all middleware or none. I can spin up N instances and run my tests in parallel.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: