blob: fe6763e05584e6edb10f6785896d11edb580684d [file] [log] [blame]
Carlos Sanchezf7c0eab2016-08-14 10:43:48 +02001#!/usr/bin/env bats
2
3SUT_IMAGE=bats-jenkins
4SUT_CONTAINER=bats-jenkins
5
6load 'test_helper/bats-support/load'
7load 'test_helper/bats-assert/load'
8load test_helpers
9
10@test "build image" {
11 cd $BATS_TEST_DIRNAME/..
Carlos Sanchez59d9ef62016-11-09 13:08:41 +010012 docker_build -t $SUT_IMAGE .
Carlos Sanchezf7c0eab2016-08-14 10:43:48 +020013}
14
15@test "clean test containers" {
16 cleanup $SUT_CONTAINER
17}
18
19@test "test multiple JENKINS_OPTS" {
20 # running --help --version should return the version, not the help
21 local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/')
22 # need the last line of output
Carlos Sanchez3e58be92016-09-16 18:32:23 -070023 assert "${version}" docker run --rm -e JENKINS_OPTS="--help --version" --name $SUT_CONTAINER -P $SUT_IMAGE | tail -n 1
Carlos Sanchezf7c0eab2016-08-14 10:43:48 +020024}
25
26@test "test jenkins arguments" {
27 # running --help --version should return the version, not the help
28 local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/')
29 # need the last line of output
Carlos Sanchez3e58be92016-09-16 18:32:23 -070030 assert "${version}" docker run --rm --name $SUT_CONTAINER -P $SUT_IMAGE --help --version | tail -n 1
Carlos Sanchezf7c0eab2016-08-14 10:43:48 +020031}
32
33@test "create test container" {
34 docker run -d -e JAVA_OPTS="-Duser.timezone=Europe/Madrid -Dhudson.model.DirectoryBrowserSupport.CSP=\"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';\"" --name $SUT_CONTAINER -P $SUT_IMAGE
35}
36
37@test "test container is running" {
38 sleep 1 # give time to eventually fail to initialize
39 retry 3 1 assert "true" docker inspect -f {{.State.Running}} $SUT_CONTAINER
40}
41
42@test "Jenkins is initialized" {
43 retry 30 5 test_url /api/json
44}
45
46@test "JAVA_OPTS are set" {
47 local sed_expr='s/<wbr>//g;s/<td class="pane">.*<\/td><td class.*normal">//g;s/<t.>//g;s/<\/t.>//g'
48 assert 'default-src &#039;self&#039;; script-src &#039;self&#039; &#039;unsafe-inline&#039; &#039;unsafe-eval&#039;; style-src &#039;self&#039; &#039;unsafe-inline&#039;;' \
49 bash -c "curl -fsSL --user \"admin:$(get_jenkins_password)\" $(get_jenkins_url)/systemInfo | sed 's/<\/tr>/<\/tr>\'$'\n/g' | grep '<td class=\"pane\">hudson.model.DirectoryBrowserSupport.CSP</td>' | sed -e '${sed_expr}'"
50 assert 'Europe/Madrid' \
51 bash -c "curl -fsSL --user \"admin:$(get_jenkins_password)\" $(get_jenkins_url)/systemInfo | sed 's/<\/tr>/<\/tr>\'$'\n/g' | grep '<td class=\"pane\">user.timezone</td>' | sed -e '${sed_expr}'"
52}
53
54@test "clean test containers" {
55 cleanup $SUT_CONTAINER
56}