theseus-rs / postgresql-embedded

Embed PostgreSQL database
Apache License 2.0
80 stars 12 forks source link

[Advice][Discussion] Using postgresql_embedded for testing #128

Closed manuelarte closed 2 months ago

manuelarte commented 2 months ago

Hi,

I am using postgres embedded for testing, right now I have something like this:

#[cfg(test)]
mod tests {
    ... // imports

    #[tokio::test]
    async fn test_one() -> Result<(), Error> {
        let database_name = "test";
        let settings = Settings {
            port: 5435,
            ..Default::default()
        };
        let postgresql = setup(database_name, settings).await?;
        {
            // rest of the test
        }
        teardown(postgresql, database_name).await?;

        Ok(())
    }

    #[tokio::test]
    async fn test_two() -> Result<(), Error> {
        let database_name = "test";
        let settings = Settings {
            port: 5436,
            ..Default::default()
        };
        let postgresql = setup(database_name, settings).await?;
        {
            // rest of the test
        }
        teardown(postgresql, database_name).await?;

        Ok(())
    }
}

But I am repeating the same pattern with

let postgresql = setup(database_name, settings).await?;
...
teardown(postgresql, database_name).await?;

Is this the best approach? Becuase while developing the tests, sometimes I get the rate limiting when downloading the binaries, so I was wondering if it's possible to:

Thanks

brianheineman commented 2 months ago

Hello @manuelarte, you can likely address the issue by specifying an exact version number to use; see: https://github.com/theseus-rs/postgresql-embedded/issues/102#issuecomment-2207305748

manuelarte commented 2 months ago

I changed my code to use an exact version, thanks @brianheineman