0

TLDR: org.testcontainers:postgresql:jar:1.18.3 seems to ignore certain settings.


I'm trying to use testcontainers postgresql for unit tests in my java app. I've read a bunch of articles/questions about this, including tc-with-podman-in-java-tests,

Back when we were allowed to use docker desktop, it worked fine. But now I'm trying to do this with podman (I'm not attached to podman, but I have tried other things and can't get testcontainers to use them either).

From what I've read, to use podman, I have to set some things in my ~/.testcontainers.properties.

docker.host=unix:///tmp/podman.sock                                                                                                                                                           
ryuk.disabled=true
testcontainers.ryuk.disabled=true
testcontainers.checks.disable=true
testcontainers.reuse.enable=true

# maybe one of these will work?
TESTCONTAINERS_REUSE_ENABLE=true
REUSE_ENABLE=true
reuse.enable=true

But when I do that, ryuk runs anyway, throws an exception, and exits the whole thing. It looks to me as though TestContainersConfiguration.loadConfiguration passes in System.getenv() as the environment, and that RyukResourceReaper.init doesn't look at the userProperties having ryuk being disabled, but it checks the environment variables for TESTCONTAINERS_REUSE_ENABLE.

I tried GenericContainer.setEnv(), but that sets the container env, it doesn't seem to affect the test for TESTCONTAINERS_REUSE_ENABLE.

Also, I discovered that I could put environment variables in my pom, but even that had an issue.

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.1.2</version>
                    <configuration>                                                                                                                                                       
                        <environmentVariables>                                                                                                                                                
                            <TESTCONTAINERS_RYUK_DISABLED>true</TESTCONTAINERS_RYUK_DISABLED>                                                                                                 
                            <TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>                                                                                                   
                        </environmentVariables>                                                                                                                                               
                    </configuration>

yielded TESTCONTAINERS_REUSE_ENABLE of "true". Note that isn't true. And with the quotes, Boolean.parse returns false.

What I'm doing right now is terrible. I'm using reflection to make the System.getenv() map modifiable, and adding to it. I'm sure this isn't the way it's supposed to work.

How is it supposed to work? I'm on a mac in case it matters.

FWIW, my code (minus the hacks to set env vars) is very simple. I don't think I'm doing anything crazy here.

        PostgreSQLContainer<?> psc = new PostgreSQLContainer<>("postgres:13.10");
        psc.start();
        psc.createConnection("");
user3742898
  • 343
  • 1
  • 2
  • 9

1 Answers1

0

Export the following env vars in your terminal

export DOCKER_HOST=unix://$(podman machine inspect --format '{{.ConnectionInfo.PodmanSocket.Path}}')
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock

If in rootless mode then add

export TESTCONTAINERS_RYUK_DISABLED=true

If in rootful mode then add

export TESTCONTAINERS_RYUK_PRIVILEGED=true
Eddú Meléndez
  • 6,107
  • 1
  • 26
  • 35