diff --git a/src/advanced/testing.md b/src/advanced/testing.md index 5e4a572..4e401eb 100644 --- a/src/advanced/testing.md +++ b/src/advanced/testing.md @@ -105,9 +105,15 @@ func TestMockDB(t *testing.T) { err = server.ReplaceDB(dialector) //... + + mock.ExpectClose() } ``` +:::tip +Test servers automatically close the database in a test cleanup hook. If you are using `go-sqlmock`, this will generate an error for unexpected `Close` unless you add `mock.ExpectClose()` at the very end of your test. +::: + ## HTTP Tests You may want to write tests that simulate how a client would interact with your API through HTTP calls. In order to do so, use the test server's `TestRequest(*http.Request)` method. It will execute the request all the way from the router's `ServeHTTP()` implementation. Therefore, the request's lifecycle will be executed from start to finish.