Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using another user for the postgres testcontainer #382

Open
morkonom opened this issue Nov 8, 2024 · 0 comments
Open

Using another user for the postgres testcontainer #382

morkonom opened this issue Nov 8, 2024 · 0 comments

Comments

@morkonom
Copy link

morkonom commented Nov 8, 2024

Hi!

Is there a way to add a user to the postgres testcontainer during startup?

We want to run tests that assert row level security. The user set up for the testcontainer has the properties SUPERUSER and BYPASSRLS so it is not really suited for that type of testing. I would like to create another user for running the actual tests (or downgrade the user during tests, if possible?).

I've come across two ways of solving this in the Java implementation, but it does not seem to be available for the Scala version. One is by populating the database with the user with an init script.
new PostgreSQLContainer("postgres:12").withInitScript("db/init.sql")

Another suggestion is by copying a file to a folder that will be executed at startup. But this functionality also seems to be missing from the Scala implementation.

new PostgreSQLContainer("postgres:12")
                    .withCopyFileToContainer(
                        MountableFile.forClasspathResource("init.sql"), 
                        "/docker-entrypoint-initdb.d/init.sql"
                     );

Is there another way?

@morkonom morkonom changed the title Using another user for the posgres testcontainer Using another user for the postgres testcontainer Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant