Skip to content

Using another user for the postgres testcontainer #382

Open
@morkonom

Description

@morkonom

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions