Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
CI: Run cucumber specs (elastic#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya authored Apr 6, 2021
1 parent a9ada6a commit ee0fbdd
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
1 change: 1 addition & 0 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def runScript(Map params = [:]){
dir("${BASE_DIR}"){
sleep randomNumber(min:10, max: 30)
dockerLogin(secret: "${DOCKER_SECRET}", registry: "${DOCKER_REGISTRY}")
sh(label: "Run BDD tests", script: "./spec/scripts/features.sh ${ruby}")
sh("./spec/scripts/spec.sh ${ruby} ${framework}")
}
}
Expand Down
17 changes: 17 additions & 0 deletions bin/run-bdd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

specific_feature=$1

export CUCUMBER_PUBLISH_QUIET=true

if [[ $specific_feature = '' ]]; then
echo 'Running all features'

echo "========================================"
cucumber
else
echo "Running only $specific_feature"

cucumber $specific_feature
fi
2 changes: 1 addition & 1 deletion bin/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ if [[ $specific_spec = '' ]]; then
else
echo "Running only $specific_spec"

runRspec $1
runRspec $specific_spec
fi
4 changes: 2 additions & 2 deletions features/step_definitions/api_key_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def config
headers[:Authorization].include?(config.api_key)
end

When('a secret_token is set in the config') do
config.secret_token = 'abcde'
When('a secret_token is set to {string} in the config') do |api_key|
config.secret_token = api_key
end

When('an api key is not set in the config') do
Expand Down
53 changes: 53 additions & 0 deletions spec/scripts/features.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
#
# Test the given docker ruby image. Optionally to filter what test
# to be triggered otherwise all of them.
#
# NOTE: It's required to be launched inside the root of the project.
#
# Usage:
# All feature files: ./spec/scripts/features.sh jruby:9.1 sinatra-2.0
# One feature file: ./spec/scripts/features.sh jruby:9.1 sinatra-2.0 "features/step_definitions/stepdefs.rb"
#
set -ex

if [ $# -lt 1 ]; then
echo "Arguments missing"
exit 2
fi

IMAGE_NAME=${1}
TEST=${2}
VERSION=$(echo "${IMAGE_NAME}" | cut -d":" -f2)

cd spec

IMAGE_NAME=${IMAGE_NAME} RUBY_VERSION=${VERSION} USER_ID="$(id -u):$(id -g)" docker-compose up -d mongodb

## Customise the docker container to enable the access to the internal of the jdk
## for the jruby docker images.
JDK_JAVA_OPTIONS=''
JRUBY_OPTS=''
if [[ $RUBY_IMAGE == *"jruby"* ]]; then
# https://github.com/jruby/jruby/issues/4834#issuecomment-343371742
JDK_JAVA_OPTIONS="--illegal-access=permit $(echo --add-opens=java.base/{java.lang,java.security,java.util,java.security.cert,java.util.zip,java.lang.reflect,java.util.regex,java.net,java.io,java.lang}=ALL-UNNAMED)"
JRUBY_OPTS="--debug"
fi

CLEAN_IMAGE_NAME=$(echo $IMAGE_NAME | sed s/:/-/ )

docker build --build-arg "RUBY_IMAGE=${IMAGE_NAME}" -t "apm-agent-ruby:${VERSION}" .

IMAGE_NAME=${IMAGE_NAME} RUBY_VERSION=${VERSION} USER_ID="$(id -u):$(id -g)" \
docker-compose -f ../docker-compose.yml run \
-e INCLUDE_SCHEMA_SPECS=1 \
-e JDK_JAVA_OPTIONS="${JDK_JAVA_OPTIONS}" \
-e JRUBY_OPTS="${JRUBY_OPTS}" \
-e HOME="/tmp" \
-v "$(dirname "$(pwd)"):/app" \
-w /app \
--rm ruby_rspec \
/bin/bash -c "\
gem install rake && \
bundle update && \
timeout -s9 15m bin/run-bdd ${TEST}"

0 comments on commit ee0fbdd

Please sign in to comment.