Skip to content

Commit e2fd19f

Browse files
committed
add helper test.sh script and Vagrantfile to have reproducible tests against PostgreSQL
1 parent a04519e commit e2fd19f

File tree

5 files changed

+95
-3
lines changed

5 files changed

+95
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.iml
2+
.vagrant
23
.DS_Store
34
.project
45
.classpath
@@ -8,4 +9,4 @@
89
nbproject/
910
target/
1011
gh-pages/
11-
atlassian-ide-plugin.xml
12+
atlassian-ide-plugin.xml

Vagrantfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5+
VAGRANTFILE_API_VERSION = "2"
6+
7+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8+
9+
config.vm.box = "ubuntu-trusty-14.04-cloudimg"
10+
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
11+
12+
config.vm.hostname = "sprocwrapper"
13+
14+
config.vm.provider "virtualbox" do |vb|
15+
vb.customize ["modifyvm", :id, "--memory", "1024"]
16+
end
17+
18+
config.vm.provision "shell", path: "vagrant/setup.sh"
19+
20+
end

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5252
<spring.version>3.2.3.RELEASE</spring.version>
5353
<postgresql.version>9.2-1003-jdbc4</postgresql.version>
54+
5455
</properties>
5556

5657
<build>
@@ -104,7 +105,7 @@
104105
<groupId>junit</groupId>
105106
<artifactId>junit</artifactId>
106107
<scope>test</scope>
107-
<version>4.10</version>
108+
<version>4.12</version>
108109
</dependency>
109110
<dependency>
110111
<groupId>org.springframework</groupId>
@@ -265,6 +266,9 @@
265266
<sqlCommand>
266267
CREATE DATABASE ${test.db.name1} TEMPLATE template1;
267268
CREATE DATABASE ${test.db.name2} TEMPLATE template1;
269+
CREATE ROLE zalando_api_owner;
270+
CREATE ROLE zalando_api_executor;
271+
CREATE ROLE zalando_api_usage;
268272
</sqlCommand>
269273
<onError>continue</onError>
270274
</configuration>
@@ -281,6 +285,7 @@
281285
<driver>org.postgresql.Driver</driver>
282286
<url>jdbc:postgresql://${test.db.host}:${test.db.port}/${test.db.name1}</url>
283287
<sqlCommand>
288+
CREATE EXTENSION hstore;
284289
DROP SCHEMA IF EXISTS ztest_schema1 CASCADE;
285290
DROP SCHEMA IF EXISTS ztest_schema2 CASCADE;
286291
</sqlCommand>
@@ -307,7 +312,7 @@
307312
</fileset>
308313
</configuration>
309314
</execution>
310-
315+
311316
<!-- execution against database 2 -->
312317
<execution>
313318
<id>drop-schemas-database2</id>
@@ -319,6 +324,7 @@
319324
<driver>org.postgresql.Driver</driver>
320325
<url>jdbc:postgresql://${test.db.host}:${test.db.port}/${test.db.name2}</url>
321326
<sqlCommand>
327+
CREATE EXTENSION hstore;
322328
DROP SCHEMA IF EXISTS ztest_schema1 CASCADE;
323329
</sqlCommand>
324330
<onError>continue</onError>

test.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
if nc -w 5 -z localhost 5432; then
4+
echo 'There is already some process listening on port 5432.'
5+
echo 'Please shutdown any existing PostgreSQL instance and re-run this script.'
6+
exit 1
7+
fi
8+
9+
export PGHOST=localhost
10+
export PGUSER=postgres
11+
export PGPASSWORD=postgres
12+
export PGDATABASE=local_zmon_db
13+
14+
container=$(docker ps | grep postgres:9.3.5)
15+
if [ -z "$container" ]; then
16+
docker rm postgres
17+
echo 'Starting PostgreSQL instance..'
18+
docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d postgres:9.3.5
19+
fi
20+
21+
until nc -w 5 -z localhost 5432; do
22+
echo 'Waiting for Postgres port..'
23+
sleep 3
24+
done
25+
26+
sleep 5
27+
28+
echo 'Running tests..'
29+
mvn clean verify -Pintegration-test
30+
31+
echo 'Stopping PostgreSQL instance..'
32+
docker stop postgres

vagrant/setup.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
apt-get remove --purge -y puppet chef
4+
apt-get autoremove -y
5+
6+
if [ ! -x "/usr/bin/docker" ]; then
7+
8+
# add Docker repo
9+
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
10+
echo 'deb https://get.docker.io/ubuntu docker main' > /etc/apt/sources.list.d/docker.list
11+
12+
set +e
13+
until apt-get update; do
14+
# TODO: this should not even be necessary
15+
echo 'apt-get update failed, retrying..'
16+
rm -fr /var/lib/apt/lists/partial
17+
sleep 1
18+
done
19+
set -e
20+
21+
# Docker
22+
apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confold" apparmor lxc-docker
23+
fi
24+
25+
adduser vagrant docker
26+
27+
apt-get install -y postgresql-client maven openjdk-7-jdk
28+
29+
echo 'localhost:5432:*:postgres:postgres' > /root/.pgpass
30+
chmod 600 /root/.pgpass
31+
cp /root/.pgpass /home/vagrant/.pgpass
32+
33+
docker pull postgres:9.3.5

0 commit comments

Comments
 (0)