5

I'm currently building an application with actix-web and sqlx. What I've build as an architecture is very similar to this source.

This is basically a trait wrapping the db access, so far so good. But this assumes every single method will get a connection from the pool and execute it. There's no way to share a connection for a transactional workflow (e.g. SELECT FOR UPDATE ... process ... UPDATE).

With which achitecture or library could I achieve this?

Regyn
  • 585
  • 3
  • 17
  • You could consider not doing SQL mocks in the first place. I much prefer having a set of test data setup scripts and using a real database service. That avoids all of the problems of having a mock that is out of touch with reality. Sure, this is integration testing. But this is SQL, it expects to be going out of process in the first place. – Zan Lynx Jun 04 '21 at 20:49
  • 1
    @ZanLynx Problem is that then I cannot even test things like register_user_exists_test. Like mocking that user_repo will return 1 user. Yes I could test the service layer with SQL mocks. But starting testcontainers for such simple tests takes enormous time. Also not upper layer, every single one will require a db to run – Regyn Jun 04 '21 at 21:26
  • Don't destroy the DB container for every test! Geez. Test setup scripts drop the tables and rebuild it in milliseconds. – Zan Lynx Jun 05 '21 at 01:01
  • 2
    Not on every test, but there’s a reason we’ve integration and unit tests. The logic that a user shall not be registered when the username is taken should run as a unit test, without needing a test db. – Regyn Jun 05 '21 at 20:05

0 Answers0