I'm trying to make sure I start with the actual problem. I have started writing a classic crud application with a database and I want to run isolated tests. looking at how rails does this tests run in a transaction make sense.
I've got to the following setup. I have this test:
pub fn create_and_show_note_test() {
use context <- test_context()
let request = create_note_request("unit tests", "unit tests are better")
let response = router.route(request, context)
assert response.status == 303
let assert Ok(location) = response.get_header(response, "location")
let request =
simulate.request(http.Get, location)
|> as_web_user("peter")
let response = router.route(request, context)
assert response.status == 200
let body = simulate.read_body(response)
assert string.contains(body, "unit tests")
}
and test_context helper:
fn test_context(then) {
dot_env.new()
|> dot_env.set_path(".env")
|> dot_env.set_debug(True)
|> dot_env.load
let assert Ok(config) = db.from_env()
let assert Ok(conn) = db.start(config)
let assert Error(pog.TransactionRolledBack(Nil)) =
pog.transaction(conn.data, fn(db) {
let context =
config.Config(db:)
then(context)
Error(Nil)
})
}
I like this approach but I am not getting the error.
sorry, too many clients already
How should I solve this? I've tried a few things but open to any suggestion really.