[HN Gopher] Pgtemp: The easiest way to write tests with Postgres...
       ___________________________________________________________________
        
       Pgtemp: The easiest way to write tests with Postgres in Rust,
       without Docker
        
       Author : ben_s
       Score  : 49 points
       Date   : 2024-02-17 09:18 UTC (13 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | peter_l_downs wrote:
       | Interesting idea to implement a proxy that does something on each
       | new connection. I'll have to think about that but very cool
       | concept that lets this work for tests written in any language.
       | 
       | Will each testcase need to run migrations after connecting for
       | the first time? Also, I'm used to using clients which lazily pool
       | connections, do they still work with this model?
       | 
       | Op, I'd be curious what you think of my project pgtestdb, which
       | takes a different approach: use a single server, but create new
       | databases each time. Maybe there is some middle ground where a
       | proxy creates a new cloned db after each connection?
       | https://github.com/peterldowns/pgtestdb
        
         | thom wrote:
         | I assume the idea here is similar to other embedded Postgres
         | libraries - you create a template database that is very fast to
         | copy on startup (or you manually copy the correct files which
         | is even faster) so you don't need to run migrations. In our
         | tests on one of the JVM equivalents the overhead is about 20ms
         | per test which is entirely tolerable. Making this language
         | agnostic is really interesting though.
        
           | peter_l_downs wrote:
           | Yeah, the parent project mentions that you can use pg_dump
           | and pg_restore, but the examples don't seem to show that (or
           | I'm misreading them.) My project uses template databases to
           | do exactly what you said. Definitely fast and definitely
           | nice.
        
       | cpursley wrote:
       | Cool, much appreciated (esp no Docker). Added to test section in
       | my "Postgres Is Enough gist:
       | https://gist.github.com/cpursley/c8fb81fe8a7e5df038158bdfe0f...
        
       | pmkelly4444 wrote:
       | extremely useful
        
       | rodorgas wrote:
       | Ideally, integration tests should not touch a real database. That
       | would be more of an end-to-end test, that could be actually
       | monitoring.
       | 
       | But mocking things are hard on Rust because of its strong type
       | system, so this project can be useful.
        
       ___________________________________________________________________
       (page generated 2024-02-17 23:01 UTC)