blob: 01f42fed5a0ecbf8709db6c35e65c0d2cbc1ddc2 [file] [log] [blame]
Thomas LEVEIL58695bb2015-09-04 21:51:10 +00001#!/usr/bin/env bats
2
3SUT_IMAGE=bats-jenkins
4SUT_CONTAINER=bats-jenkins
5
6load test_helpers
7
8@test "build image" {
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +01009 cd $BATS_TEST_DIRNAME/..
10 docker build -t $SUT_IMAGE .
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000011}
12
13@test "clean test containers" {
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010014 cleanup $SUT_CONTAINER
15}
16
17@test "test multiple JENKINS_OPTS" {
18 # running --help --version should return the version, not the help
Carlos Sanchez0c987822016-03-16 08:42:03 +010019 local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/')
Carlos Sanchez2d68b192016-04-20 13:26:59 +020020 # need the last line of output
21 assert "${version}" docker run --rm -ti -e JENKINS_OPTS="--help --version" --name $SUT_CONTAINER -P $SUT_IMAGE | tail -n 1
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010022}
23
24@test "test jenkins arguments" {
25 # running --help --version should return the version, not the help
Carlos Sanchez0c987822016-03-16 08:42:03 +010026 local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/')
Carlos Sanchez2d68b192016-04-20 13:26:59 +020027 # need the last line of output
28 assert "${version}" docker run --rm -ti --name $SUT_CONTAINER -P $SUT_IMAGE --help --version | tail -n 1
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000029}
30
31@test "create test container" {
Carlos Sanchezc24ef822016-02-29 12:10:31 +010032 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
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000033}
34
35@test "test container is running" {
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010036 sleep 1 # give time to eventually fail to initialize
37 retry 3 1 assert "true" docker inspect -f {{.State.Running}} $SUT_CONTAINER
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000038}
39
40@test "Jenkins is initialized" {
41 retry 30 5 test_url /api/json
42}
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010043
Carlos Sanchezc24ef822016-02-29 12:10:31 +010044@test "JAVA_OPTS are set" {
45 local sed_expr='s/<wbr>//g;s/<td class="pane">.*<\/td><td class.*normal">//g;s/<t.>//g;s/<\/t.>//g'
46 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;;' \
Carlos Sanchez5a51d0a2016-04-21 13:50:25 +020047 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}'"
Carlos Sanchezc24ef822016-02-29 12:10:31 +010048 assert 'Europe/Madrid' \
Carlos Sanchez5a51d0a2016-04-21 13:50:25 +020049 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}'"
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010050}
Carlos Sanchez177b25f2016-02-29 13:53:22 +010051
Carlos Sanchez2d72a182016-04-20 13:27:15 +020052@test "plugins are installed" {
Carlos Sanchez3e8e9482016-04-20 13:04:48 +020053 docker build -t $SUT_IMAGE-plugins $BATS_TEST_DIRNAME/plugins
Carlos Sanchez2d72a182016-04-20 13:27:15 +020054 assert "maven-plugin.jpi maven-plugin.jpi.pinned" docker run -ti --rm $SUT_IMAGE-plugins ls /var/jenkins_home/plugins | sed -e 's/ / /'
Carlos Sanchez3e8e9482016-04-20 13:04:48 +020055}
56
Carlos Sanchez177b25f2016-02-29 13:53:22 +010057@test "clean test containers" {
58 cleanup $SUT_CONTAINER
59}