Skip to content

Commit 8aea9df

Browse files
committed
Add support for running Testkit as part of Maven build
1 parent 3bf4add commit 8aea9df

File tree

5 files changed

+214
-1
lines changed

5 files changed

+214
-1
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<module>driver</module>
5151
<module>examples</module>
5252
<module>testkit-backend</module>
53+
<module>testkit-tests</module>
5354
</modules>
5455

5556
<licenses>

testkit-tests/pom.xml

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
3+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.neo4j.driver</groupId>
8+
<artifactId>neo4j-java-driver-parent</artifactId>
9+
<version>4.3-SNAPSHOT</version>
10+
<relativePath>..</relativePath>
11+
</parent>
12+
13+
<artifactId>testkit-tests</artifactId>
14+
15+
<name>Neo4j Java Driver Testkit Tests</name>
16+
<description>Tests this driver using Testkit.</description>
17+
18+
<properties>
19+
<rootDir>${project.basedir}/..</rootDir>
20+
21+
<testkit.version>4.3</testkit.version>
22+
<!-- See the testkit-custom-args profile if you want to customize this on individual runs. -->
23+
<testkit.args>--tests TESTKIT_TESTS INTEGRATION_TESTS STUB_TESTS STRESS_TESTS TLS_TESTS</testkit.args>
24+
<testkit.timeout>7200000</testkit.timeout>
25+
26+
<docker-maven-plugin.version>0.36.1</docker-maven-plugin.version>
27+
<docker.showLogs>true</docker.showLogs>
28+
</properties>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>io.fabric8</groupId>
34+
<artifactId>docker-maven-plugin</artifactId>
35+
</plugin>
36+
</plugins>
37+
38+
<pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<groupId>io.fabric8</groupId>
42+
<artifactId>docker-maven-plugin</artifactId>
43+
<version>${docker-maven-plugin.version}</version>
44+
45+
<configuration>
46+
<images>
47+
<image>
48+
<name>testkit-launcher:%v</name>
49+
50+
<build>
51+
<contextDir>${project.basedir}/src/main/docker</contextDir>
52+
</build>
53+
54+
<run>
55+
<!--
56+
A sanitized version of the image’s short name from which this container is created.
57+
As this Maven plugin does not currently remove Docker containers when Maven build is interrupted,
58+
a unique name should prevent running multiple concurrent builds.
59+
-->
60+
<containerNamePattern>%n</containerNamePattern>
61+
<wait>
62+
<exit>0</exit>
63+
<time>${testkit.timeout}</time>
64+
</wait>
65+
<env>
66+
<TESTKIT_CHECKOUT_PATH>${project.build.directory}/testkit</TESTKIT_CHECKOUT_PATH>
67+
<TESTKIT_VERSION>${testkit.version}</TESTKIT_VERSION>
68+
<TESTKIT_ARGS>${testkit.args}</TESTKIT_ARGS>
69+
<TEST_DRIVER_NAME>java</TEST_DRIVER_NAME>
70+
<TEST_DRIVER_REPO>${rootDir}</TEST_DRIVER_REPO>
71+
<TEST_SKIP_BUILD>true</TEST_SKIP_BUILD>
72+
</env>
73+
<volumes>
74+
<bind>
75+
<!--
76+
Testkit requires access to Docker to launch other containers.
77+
This is achieved by passing through the host's Docker socket.
78+
-->
79+
<volume>/var/run/docker.sock:/var/run/docker.sock</volume>
80+
<!--
81+
Testkit launches other containers and shares sources with them via volumes.
82+
Given that Testkit runs in the container and uses the host's Docker instance,
83+
the filesystem paths it uses must exist on the host system.
84+
This is achieved by using the same path as on the host system.
85+
-->
86+
<volume>${rootDir}:${rootDir}</volume>
87+
</bind>
88+
</volumes>
89+
</run>
90+
</image>
91+
</images>
92+
</configuration>
93+
94+
<executions>
95+
<execution>
96+
<id>build-testkit-launcher</id>
97+
<phase>pre-integration-test</phase>
98+
<goals>
99+
<goal>build</goal>
100+
</goals>
101+
</execution>
102+
<execution>
103+
<id>run-testkit</id>
104+
<phase>integration-test</phase>
105+
<goals>
106+
<!-- Testkit is expected to exit automatically. -->
107+
<goal>start</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
</plugins>
113+
</pluginManagement>
114+
</build>
115+
116+
<profiles>
117+
<!-- Skips running Testkit when tests are skipped. -->
118+
<profile>
119+
<id>skip-testkit</id>
120+
<activation>
121+
<property>
122+
<name>skipTests</name>
123+
</property>
124+
</activation>
125+
<properties>
126+
<docker.skip>true</docker.skip>
127+
</properties>
128+
</profile>
129+
<!-- Skips running Testkit in TeamCity as it is launched separately. -->
130+
<profile>
131+
<id>skip-testkit-teamcity</id>
132+
<activation>
133+
<property>
134+
<name>env.TEAMCITY_VERSION</name>
135+
</property>
136+
</activation>
137+
<properties>
138+
<docker.skip>true</docker.skip>
139+
</properties>
140+
</profile>
141+
<!--
142+
Enables running Testkit when other tests are skipped.
143+
Usage example: mvn clean verify -DskipTests -P testkit-tests
144+
-->
145+
<profile>
146+
<id>testkit-tests</id>
147+
<properties>
148+
<docker.skip>false</docker.skip>
149+
</properties>
150+
</profile>
151+
<!--
152+
Enables passing custom arguments to Testkit and also enables running Testkit when other tests are skipped.
153+
Usage example: mvn clean verify -DskipTests -DtestkitArgs='args' (for instance, you can run stub tests only by setting the tests argument to STUB_TESTS)
154+
-->
155+
<profile>
156+
<id>testkit-custom-args</id>
157+
<activation>
158+
<property>
159+
<name>testkitArgs</name>
160+
</property>
161+
</activation>
162+
<properties>
163+
<docker.skip>false</docker.skip>
164+
<testkit.args>${testkitArgs}</testkit.args>
165+
</properties>
166+
</profile>
167+
<!--
168+
Enables docker maven plugin verbose output.
169+
For instance, this can be useful for checking build logs.
170+
-->
171+
<profile>
172+
<id>testkit-docker-verbose</id>
173+
<properties>
174+
<docker.verbose>true</docker.verbose>
175+
</properties>
176+
</profile>
177+
</profiles>
178+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.10.0b4-buster
2+
3+
RUN apt-get update && apt-get install -y \
4+
apt-transport-https \
5+
ca-certificates \
6+
curl \
7+
gnupg \
8+
lsb-release
9+
10+
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
11+
12+
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
13+
| tee /etc/apt/sources.list.d/docker.list > /dev/null
14+
15+
RUN apt-get update && apt-get install -y \
16+
docker-ce-cli
17+
18+
COPY /entrypoint.sh /
19+
20+
RUN chmod +x /entrypoint.sh
21+
22+
ENTRYPOINT ["/entrypoint.sh"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
rm -rf $TESTKIT_CHECKOUT_PATH
6+
git clone https://github.com/neo4j-drivers/testkit.git $TESTKIT_CHECKOUT_PATH
7+
cd $TESTKIT_CHECKOUT_PATH
8+
git checkout $TESTKIT_VERSION
9+
10+
echo "Testkit args: '$TESTKIT_ARGS'"
11+
python main.py $TESTKIT_ARGS

testkit/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
Responsible for building driver and test backend.
44
"""
55
import subprocess
6+
import os
67

78

89
def run(args):
910
subprocess.run(
1011
args, universal_newlines=True, stderr=subprocess.STDOUT, check=True)
1112

1213

13-
if __name__ == "__main__":
14+
if __name__ == "__main__" and "TEST_SKIP_BUILD" not in os.environ:
1415
run(["mvn", "clean", "install", "-P", "!determine-revision", "-DskipTests"])

0 commit comments

Comments
 (0)