micronaut-projects / micronaut-test-resources

Test resources support
Apache License 2.0
8 stars 17 forks source link

init-script-path does not work in 3.7 #122

Closed sarmbruster closed 1 year ago

sarmbruster commented 1 year ago

Expected Behavior

Assume a file src/test/resources/db/init.sql being referred in application.yml as

test-resources:
  containers:
    postgres:
      init-script-path: db/init.sql

When running e.g. ./gradlew test that file should be applied to the test database.

Actual Behaviour

It seems that test-resources server does not inherit the classpath correctly:

12:06:30.209 [default-nioEventLoopGroup-1-7] WARN  org.testcontainers.ext.ScriptUtils - Could not load classpath init script: db/init.sql

Steps To Reproduce

see description in Expected Behaviour

Environment Information

see thread on gitter as well: https://gitter.im/micronautfw/questions?at=6363a25921df5f7a54cfae9d

Example Application

can share privately if necessary

Version

3.7.2

MT-Jacobs commented 1 year ago

You beat me to it! Here's an example application with a failing test - https://github.com/MT-Jacobs/tr-workshop

sarmbruster commented 1 year ago

I case of Gradle being used as build tool this can be resolved by moving the init-script-file from src/test/resources to src/testResources/resources.

MT-Jacobs commented 1 year ago

Oh! Well that's a change in behavior then. I previously had it working fine in the test directory.

melix commented 1 year ago

Change of behavior compared to using testcontainers directly in your tests, I guess. The difference is that test resources are not executed in the test sources context: they are isolated in their own process (which is a reason why they work fine with native images).

MT-Jacobs commented 1 year ago

I definitely had this working before with Test Resources via the test sources context, but since I can't reproduce it in the example repo I provided, I'll chalk it up as it working previously by accident of my private repo configurations.

MT-Jacobs commented 1 year ago

In any event this can probably be closed as not an issue - the docs in https://github.com/micronaut-projects/micronaut-test-resources/commit/c777980acd25d6f57dc203243fbf802d439d769f clarify this behavior.