In a Spring boot Gradle app, Zonky embedded postgres is used for integration tests.
Running the integration tests as stand alone through intellij gradle tasks they all pass correctly.
Running them as part of a static-analysis Github workflow(pipeline) they fail due to Zonky.
The error itself is the following:
Run ./gradlew integrationTest --scan
Downloading https://services.gradle.org/distributions/gradle-7.4.1-bin.zip
...........10%...........20%...........30%...........40%...........50%...........60%...........70%...........80%...........90%...........100%
Welcome to Gradle 7.4.1!
Here are the highlights of this release:
- Aggregated test and JaCoCo reports
- Marking additional test source directories as tests in IntelliJ
- Support for Adoptium JDKs in Java toolchains
For more details see https://docs.gradle.org/7.4.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
MyClassOfIntTest > initializationError FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: org.springframework.beans.factory.BeanCreationException at ConstructorResolver.java:658
Caused by: org.springframework.beans.BeanInstantiationException at SimpleInstantiationStrategy.java:185
Caused by: io.zonky.test.db.shaded.com.google.common.util.concurrent.UncheckedExecutionException at Futures.java:1546
Caused by: io.zonky.test.db.provider.ProviderException at ZonkyPostgresDatabaseProvider.java:110
Caused by: java.lang.IllegalStateException at EmbeddedPostgres.java:633
....more tests fail here and omitted for brevity
4 tests completed, 4 failed
> Task :integrationTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':integrationTest'.
> There were failing tests. See the report at: file:///__w/projectname/project_name/build/reports/tests/integrationTest/index.html
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 55s
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.4.1/userguide/command_line_interface.html#sec:command_line_warnings
10 actionable tasks: 10 executed
The build scan was not published due to a configuration problem.
The Gradle Terms of Service have not been agreed to.
For more information, please see https://gradle.com/help/plugin-terms-of-service.
Alternatively, if you are using Gradle Enterprise, specify the server location.
For more information, please see https://gradle.com/help/plugin-enterprise-config.
Error: Process completed with exit code 1.
I have tried multiple ways to configure a non-root user, as suggested in the readme of zonky, but the error still remains. For example:
- Tried to set it up in the static-analysis.yaml as follows.
- name: Create and use a test user
run: |
groupadd --system --gid 1000 test
useradd --system --gid test --uid 1000 --shell /bin/bash --create-home test
su - test
- Tried to set it up in the Dockerfile as shown in the docs.
FROM code AS tests
RUN groupadd --system --gid 1000 test
RUN useradd --system --gid test --uid 1000 --shell /bin/bash --create-home test
USER test
RUN gradle -i clean test integrationTest
- I have tried by creating a database non root user and setting it up during the schema creation in the migration scripts that are ran by flyway for the integration tests
CREATE USER non_root_user WITH PASSWORD 'custom_password';
CREATE SCHEMA myschema AUTHORIZATION non_root_user;
- I have also tried to set the non root user of the Postgres through the environment variables of the integration environment, which means I added the username/password in the zonky config on applitation-int.yaml and I set as active profile the int at the step I call gradle integrationTest.
Any suggestions are welcome.
The versions I use are the following:
'embedded-database-spring-test', version: "2.5.0"
'embedded-postgres', version: "2.0.7"
'embedded-postgres-binaries-bom', 'version': '16.4.0'
Christos Karapapas Business Ac is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.