Skip to content

Commit

Permalink
ci: run e2e tests (#148)
Browse files Browse the repository at this point in the history
It adds a stage to run the e2e teste
  • Loading branch information
kuisathaverat authored Nov 26, 2020
1 parent 2356672 commit 1375d46
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 19 deletions.
44 changes: 42 additions & 2 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pipeline {
}
}
}
stash allowEmpty: true, name: 'source', useDefaultExcludes: false, excludes: ".npm/_cacache/**"
stash allowEmpty: true, name: 'source', useDefaultExcludes: false, excludes: ".npm/_cacache/**,.nvm/.git/**"
}
}
/**
Expand Down Expand Up @@ -105,6 +105,26 @@ pipeline {
}
}

stage('E2e Test') {
steps {
withGithubNotify(context: 'E2e Test') {
cleanup()
withNodeEnv(){
dir("${BASE_DIR}"){
sh(label: 'set permissions', script: '''
chmod -R ugo+rw examples
''')
dir("__tests__/e2e"){
timeout(time: 10, unit: 'MINUTES') {
sh(label: 'run e2e tests',script: 'npm run test')
}
}
}
}
}
}
}

/**
Publish Docker images.
*/
Expand Down Expand Up @@ -173,14 +193,34 @@ def cleanup(){
unstash 'source'
}

def withNodeEnv(Map args=[:], Closure body){
def withNodeInDockerEnv(Map args=[:], Closure body){
docker.image("${NODE_DOCKER_IMAGE}").inside(" --security-opt seccomp=${SECCOMP_FILE}"){
withEnv(["HOME=${WORKSPACE}"]) {
body()
}
}
}

def withNodeEnv(Map args=[:], Closure body){
withEnv(["HOME=${WORKSPACE}"]) {
sh(label: 'install Node.js', script: '''
set +x
if [ -z "$(command -v nvm)" ]; then
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash
fi
export NVM_DIR="${HOME}/.nvm"
[ -s "${NVM_DIR}/nvm.sh" ] && \\. "${NVM_DIR}/nvm.sh"
nvm install --lts
nvm version | head -n1 > .nvm-node-version
''')
def node_version = readFile(file: '.nvm-node-version').trim()
withEnv(["PATH+NVM=${HOME}/.nvm/versions/node/${node_version}/bin"]){
body()
}
}
}

def pushDockerImage(){
dir("${BASE_DIR}"){
dockerLogin(secret: "${env.DOCKERELASTIC_SECRET}",
Expand Down
3 changes: 1 addition & 2 deletions __tests__/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ services:
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
command:
-E output.elasticsearch.hosts=["elasticsearch:9200"]

-E output.elasticsearch.hosts=["elasticsearch:9200"] --strict.perms=false --environment container
networks:
- elastic

Expand Down
11 changes: 6 additions & 5 deletions __tests__/e2e/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e
set -xe

# variables

Expand All @@ -10,9 +10,11 @@ if [ $? -ne 0 ]; then
exit 1
fi

# formatting
bold=$(tput bold)
normal=$(tput sgr0)
if [ -z "${JENKINS_URL}" ]; then
# formatting
bold=$(tput bold)
normal=$(tput sgr0)
fi

# paths
E2E_DIR="./"
Expand All @@ -32,4 +34,3 @@ echo "${bold}Starting elasticsearch , kibana and synthetics docker${normal}"
echo "" # newline

STACK_VERSION=7.10.0 docker-compose --file docker-compose.yml up --remove-orphans > ${TMP_DIR}/docker-logs.log 2>&1 &

21 changes: 11 additions & 10 deletions __tests__/e2e/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#!/usr/bin/env bash
set -e


# formatting
bold=$(tput bold)
normal=$(tput sgr0)
set -xe

if [ -z "${JENKINS_URL}" ]; then
# formatting
bold=$(tput bold)
normal=$(tput sgr0)
SLEEP_TIME="0.1"
else
SLEEP_TIME="10"
fi

# Wait for synthetics docker to start
##################################################
echo "" # newline
echo "${bold}Waiting for synthetics docker to start...${normal}"
until [ "`docker inspect -f {{.State.Running}} synthetics`" == "true" ]; do
sleep 0.1;
until [ "$(docker inspect -f {{.State.Running}} synthetics)" == "true" ]; do
sleep ${SLEEP_TIME};
done;

echo "✅ Setup completed successfully. Running e2e tests..."
Expand All @@ -22,5 +25,3 @@ echo "✅ Setup completed successfully. Running e2e tests..."
##################################################

npx @elastic/synthetics uptime.journey.ts


0 comments on commit 1375d46

Please sign in to comment.