Skip to content

Commit

Permalink
Redis can now be used as session store for portal tests. (#3)
Browse files Browse the repository at this point in the history
* Redis can now be used as session store for portal tests. See Haufe-Lexware/wicked.haufe.io#83:

* Redis sessions - refactorings preparing reading session store config from globals.json

* Redis sessions - run unit tests with and without redis sessions

* Better feature branch building - match image tags automatically

* Jenkinsfile comma missing

* Fixing detection of failed test cases... when did that disappear?
  • Loading branch information
achwie authored and DonMartin76 committed Sep 15, 2017
1 parent 34b43c0 commit ac40d7f
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 35 deletions.
26 changes: 26 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ properties([
defaultValue: 'haufelexware/wicked.',
description: 'Docker image prefix to use when testing.',
required: false
),
string(
name: 'FEATURE_BRANCH_OVERRIDE',
defaultValue: '',
description: 'Specify a feature branch you want to test with this branch of the tests. Tests will fall back to "next" images branch tag is not present.',
required: false
)
]),
pipelineTriggers([
Expand All @@ -26,6 +32,8 @@ node('docker') {
}

def dockerTag = env.BRANCH_NAME.replaceAll('/', '-')
if (params.FEATURE_BRANCH_OVERRIDE != "")
dockerTag = params.FEATURE_BRANCH_OVERRIDE.replaceAll('/', '-');

echo 'Using docker tag: ' + dockerTag
env.DOCKER_TAG = dockerTag
Expand All @@ -49,13 +57,31 @@ node('docker') {
stage('Portal Tests') {

env.BUILD_ALPINE = '';
env.REDIS_SESSIONS = '';
sh './run-portal-tests.sh'

}

stage('Portal Tests (alpine)') {

env.BUILD_ALPINE = '-alpine';
env.REDIS_SESSIONS = '';
sh './run-portal-tests.sh'

}

stage('Portal Tests (redis)') {

env.BUILD_ALPINE = '';
env.REDIS_SESSIONS = 'true';
sh './run-portal-tests.sh'

}

stage('Portal Tests (redis, alpine)') {

env.BUILD_ALPINE = '-alpine';
env.REDIS_SESSIONS = 'true';
sh './run-portal-tests.sh'

}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ $ ./run-<api|portal|kong-adapter>-tests.sh

The scripts will attempt to first build the needed docker images locally (this may take some time the first time), and then runs the integration tests on the built images.

The portal tests are run with file session store by default. If you want to run them using Redis as a session store, you can do so by running them like:

```bash
$ REDIS_SESSIONS=true ./run-portal-tests.sh
```

## Running the tests on prebuilt container images

In order to run the integration tests on already prebuilt containers (e.g. the official docker images from Haufe-Lexware), use the following syntax:
Expand Down
2 changes: 1 addition & 1 deletion api-tests-compose.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:

portal-api:
env_file: variables.env
image: ${DOCKER_PREFIX}portal-api:${DOCKER_TAG}${BUILD_ALPINE}
image: ${DOCKER_PREFIX}portal-api:${PORTAL_API_TAG}${BUILD_ALPINE}
volumes_from:
- "api-test-data"

Expand Down
2 changes: 1 addition & 1 deletion base/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ${DOCKER_PREFIX}portal-env:${DOCKER_TAG}-onbuild${BUILD_ALPINE}
FROM ${DOCKER_PREFIX}portal-env:${PORTAL_ENV_TAG}${BUILD_ALPINE}

USER root

Expand Down
6 changes: 3 additions & 3 deletions kong-adapter-tests-compose.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ services:

portal-api:
env_file: variables.env
image: ${DOCKER_PREFIX}portal-api:${DOCKER_TAG}${BUILD_ALPINE}
image: ${DOCKER_PREFIX}portal-api:${PORTAL_API_TAG}${BUILD_ALPINE}
volumes_from:
- "kong-adapter-test-data"
environment:
- "PORTAL_API_HOOK_INTERVAL=200"

portal-kong-adapter:
env_file: variables.env
image: ${DOCKER_PREFIX}portal-kong-adapter:${DOCKER_TAG}${BUILD_ALPINE}
image: ${DOCKER_PREFIX}portal-kong-adapter:${PORTAL_KONG_ADAPTER_TAG}${BUILD_ALPINE}
depends_on:
- portal-api
- kong
Expand All @@ -30,7 +30,7 @@ services:
- "POSTGRES_PASSWORD=kong"

kong:
image: ${DOCKER_PREFIX}kong:${DOCKER_TAG}
image: ${DOCKER_PREFIX}kong:${KONG_TAG}
depends_on:
- "kong-database"
links:
Expand Down
16 changes: 16 additions & 0 deletions portal-api/test/13_versionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,20 @@ describe('/confighash', function () {
done();
});
});

it('should have added a default sessionStore configuration in globals', function (done) {
request.get({
url: baseUrl + 'globals',
headers: {
'X-Config-Hash': configHash
}
}, function (err, res, body) {
assert.isNotOk(err);
assert.equal(res.statusCode, 200);
var jsonBody = utils.getJson(body);
assert.isOk(jsonBody.sessionStore, 'globals.json do not contain a sessionStore property');
assert.equal(jsonBody.sessionStore.type, 'file', 'default sessionStore.type is not equal "file"');
done();
});
});
});
7 changes: 5 additions & 2 deletions portal-tests-compose.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ services:

portal-api:
env_file: variables.env
image: ${DOCKER_PREFIX}portal-api:${DOCKER_TAG}${BUILD_ALPINE}
image: ${DOCKER_PREFIX}portal-api:${PORTAL_API_TAG}${BUILD_ALPINE}
volumes_from:
- "portal-test-data"

portal:
env_file: variables.env
image: ${DOCKER_PREFIX}portal:${DOCKER_TAG}${BUILD_ALPINE}
image: ${DOCKER_PREFIX}portal:${PORTAL_TAG}${BUILD_ALPINE}

portal-redis:
image: redis:3.2.10-alpine

networks:
default:
Expand Down
6 changes: 6 additions & 0 deletions portal/test/test-config/static/env/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
},
"PORTAL_REC2": {
"value": "Recursive"
},
"SESSION_STORE_HOST": {
"value": "portal-redis"
},
"SESSION_STORE_TYPE": {
"values": "(undefined)"
}
}
5 changes: 5 additions & 0 deletions portal/test/test-config/static/env/test-redis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"SESSION_STORE_TYPE": {
"value": "redis"
}
}
6 changes: 5 additions & 1 deletion portal/test/test-config/static/env/test.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{}
{
"SESSION_STORE_TYPE": {
"value": "file"
}
}
4 changes: 4 additions & 0 deletions portal/test/test-config/static/globals.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"requiredGroup": "dev"
}
},
"sessionStore": {
"type": "${SESSION_STORE_TYPE}",
"host": "${SESSION_STORE_HOST}"
},
"auth": {
"local": {
"useLocal": true,
Expand Down
35 changes: 30 additions & 5 deletions run-api-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e

buildLocal=""

export NODE_ENV=test

if [ -z "$DOCKER_PREFIX" ]; then
echo Env var DOCKER_PREFIX is not set, assuming local build.
export DOCKER_PREFIX=local_
Expand Down Expand Up @@ -44,29 +46,43 @@ thisPath=`pwd`

echo Docker logs go into docker-api${BUILD_ALPINE}.log.

export PORTAL_ENV_TAG=${DOCKER_TAG}-onbuild
export PORTAL_API_TAG=${DOCKER_TAG}

if [ ! -z "$buildLocal" ]; then

echo Building images locally.

pushd ../wicked.portal-env
echo Building Environment docker image...
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-env:${DOCKER_TAG}-onbuild${BUILD_ALPINE} . >> $thisPath/docker-api${BUILD_ALPINE}.log
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-env:${PORTAL_ENV_TAG}${BUILD_ALPINE} . >> $thisPath/docker-api${BUILD_ALPINE}.log
popd

pushd ../wicked.portal-api
echo Building API docker image...
perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' Dockerfile.template > Dockerfile${BUILD_ALPINE}
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-api:${DOCKER_TAG}${BUILD_ALPINE} . >> $thisPath/docker-api${BUILD_ALPINE}.log
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-api:${PORTAL_API_TAG}${BUILD_ALPINE} . >> $thisPath/docker-api${BUILD_ALPINE}.log
popd

else

echo Using prebuilt images:
echo DOCKER_PREFIX=${DOCKER_PREFIX}
echo DOCKER_TAG=${DOCKER_TAG}${BUILD_ALPINE}

dockerTag=${DOCKER_TAG}
echo DOCKER_TAG=${dockerTag}

# Magic image matching?
if [[ "$DOCKER_PREFIX" == "haufelexware/wicked." ]]; then
echo "INFO: Resolving image names for tag ${dockerTag}"
docker pull haufelexware/wicked.portal-env:next-onbuild-alpine
export PORTAL_ENV_TAG=$(docker run --rm haufelexware/wicked.portal-env:next-onbuild-alpine node node_modules/portal-env/getMatchingTag.js haufelexware wicked.portal-env ${dockerTag})
export PORTAL_API_TAG=$(docker run --rm haufelexware/wicked.portal-env:next-onbuild-alpine node node_modules/portal-env/getMatchingTag.js haufelexware wicked.portal-api ${dockerTag})
fi
fi

echo "INFO: PORTAL_ENV_TAG=${PORTAL_ENV_TAG}"
echo "INFO: PORTAL_API_TAG=${PORTAL_API_TAG}"

echo Templating Dockerfile for test base and compose file...

perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' base/Dockerfile.template > base/Dockerfile
Expand All @@ -75,7 +91,7 @@ perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;su
if [ -z "$buildLocal" ]; then
echo Using prebuilt images: Pulling images...
docker-compose -p wickedportaltest -f api-tests-compose.yml pull
docker pull ${DOCKER_PREFIX}portal-env:${DOCKER_TAG}-onbuild${BUILD_ALPINE}
docker pull ${DOCKER_PREFIX}portal-env:${PORTAL_ENV_TAG}${BUILD_ALPINE}
fi

echo Building Test base container...
Expand All @@ -92,6 +108,10 @@ if ! docker-compose -p wickedportaltest -f api-tests-compose.yml up --abort-on-c
failedTests="true"
fi
echo Copying test results...
if [ -d test_results ]; then
echo "INFO: Cleaning up..."
rm -rf test_results
fi
if ! docker cp wickedportaltest_api-test-data_1:/usr/src/app/test_results .; then
echo ERROR: The test results are not available.
failedTests="true"
Expand All @@ -107,4 +127,9 @@ cat test_results/api-test.log

echo Detailed logs are in api-test${BUILD_ALPINE}.log.

if [ -f test_results/API_FAILED ]; then
echo "ERROR: Some test cases failed."
exit 1
fi

echo Done.
51 changes: 38 additions & 13 deletions run-kong-adapter-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e

buildLocal=""

export NODE_ENV=test

if [ -z "$DOCKER_PREFIX" ]; then
echo Env var DOCKER_PREFIX is not set, assuming local build.
export DOCKER_PREFIX=local_
Expand Down Expand Up @@ -42,6 +44,11 @@ fi
rm -f docker-kong-adapter${BUILD_ALPINE}.log
thisPath=`pwd`

export PORTAL_ENV_TAG=${DOCKER_TAG}-onbuild
export PORTAL_API_TAG=${DOCKER_TAG}
export PORTAL_KONG_ADAPTER_TAG=${DOCKER_TAG}
export KONG_TAG=${DOCKER_TAG}

echo Docker logs go into docker-kong-adapter${BUILD_ALPINE}.log.

if [ ! -z "$buildLocal" ]; then
Expand All @@ -50,41 +57,50 @@ if [ ! -z "$buildLocal" ]; then

pushd ../wicked.portal-env
echo Building Environment docker image...
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-env:${DOCKER_TAG}-onbuild . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-env:${PORTAL_ENV_TAG}${BUILD_ALPINE} . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
popd

pushd ../wicked.portal-api
echo Building API docker image...
perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' Dockerfile.template > Dockerfile${BUILD_ALPINE}
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-api:${DOCKER_TAG}${BUILD_ALPINE} . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
popd

pushd ../wicked.portal
echo Building Portal docker image...
perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' Dockerfile.template > Dockerfile${BUILD_ALPINE}
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal:${DOCKER_TAG}${BUILD_ALPINE} . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-api:${PORTAL_API_TAG}${BUILD_ALPINE} . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
popd

pushd ../wicked.portal-kong-adapter
echo Building Kong Adapter docker image...
perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' Dockerfile.template > Dockerfile${BUILD_ALPINE}
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-kong-adapter:${DOCKER_TAG}${BUILD_ALPINE} . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
docker build -f Dockerfile${BUILD_ALPINE} -t ${DOCKER_PREFIX}portal-kong-adapter:${PORTAL_KONG_ADAPTER_TAG}${BUILD_ALPINE} . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
popd

pushd ../wicked.kong
echo Building Kong docker image...
# perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' Dockerfile.template > Dockerfile
docker build -t ${DOCKER_PREFIX}kong:${DOCKER_TAG} . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
docker build -t ${DOCKER_PREFIX}kong:${KONG_TAG} . >> $thisPath/docker-kong-adapter${BUILD_ALPINE}.log
popd

else

echo Using prebuilt images:
echo DOCKER_PREFIX=$DOCKER_PREFIX
echo DOCKER_TAG=$DOCKER_TAG

dockerTag=${DOCKER_TAG}
echo DOCKER_TAG=${dockerTag}

# Magic image matching?
if [[ "$DOCKER_PREFIX" == "haufelexware/wicked." ]]; then
echo "INFO: Resolving image names for tag ${dockerTag}"
docker pull haufelexware/wicked.portal-env:next-onbuild-alpine
export PORTAL_ENV_TAG=$(docker run --rm haufelexware/wicked.portal-env:next-onbuild-alpine node node_modules/portal-env/getMatchingTag.js haufelexware wicked.portal-env ${dockerTag})
export PORTAL_API_TAG=$(docker run --rm haufelexware/wicked.portal-env:next-onbuild-alpine node node_modules/portal-env/getMatchingTag.js haufelexware wicked.portal-api ${dockerTag})
export PORTAL_KONG_ADAPTER_TAG=$(docker run --rm haufelexware/wicked.portal-env:next-onbuild-alpine node node_modules/portal-env/getMatchingTag.js haufelexware wicked.portal-kong-adapter ${dockerTag})
export KONG_TAG=$(docker run --rm haufelexware/wicked.portal-env:next-onbuild-alpine node node_modules/portal-env/getMatchingTag.js haufelexware wicked.kong ${dockerTag})
fi
fi

echo "INFO: PORTAL_ENV_TAG=${PORTAL_ENV_TAG}"
echo "INFO: PORTAL_API_TAG=${PORTAL_API_TAG}"
echo "INFO: PORTAL_KONG_ADAPTER_TAG=${PORTAL_KONG_ADAPTER_TAG}"
echo "INFO: KONG_TAG=${KONG_TAG}"

echo Templating Dockerfile for test base and compose file...

perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' base/Dockerfile.template > base/Dockerfile
Expand All @@ -93,7 +109,7 @@ perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;su
if [ -z "$buildLocal" ]; then
echo Using prebuilt images: Pulling images...
docker-compose -p wickedportaltest -f kong-adapter-tests-compose.yml pull
docker pull ${DOCKER_PREFIX}portal-env:${DOCKER_TAG}-onbuild${BUILD_ALPINE}
docker pull ${DOCKER_PREFIX}portal-env:${PORTAL_ENV_TAG}${BUILD_ALPINE}
fi

echo Building Test base container...
Expand All @@ -110,6 +126,10 @@ if ! docker-compose -p wickedportaltest -f kong-adapter-tests-compose.yml up --a
failedTests="true"
fi
echo Copying test results...
if [ -d test_results ]; then
echo "INFO: Cleaning up..."
rm -rf test_results
fi
if ! docker cp wickedportaltest_kong-adapter-test-data_1:/usr/src/app/test_results .; then
echo ERROR: The test results are not available.
failedTests="true"
Expand All @@ -125,4 +145,9 @@ cat test_results/kong-adapter-test.log

echo Detailed logs are in kong-adapter-test${BUILD_ALPINE}.log.

if [ -f test_results/KONG_FAILED ]; then
echo "ERROR: Some test cases failed."
exit 1
fi

echo Done.
Loading

0 comments on commit ac40d7f

Please sign in to comment.