Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bats |
| 2 | |
| 3 | SUT_IMAGE=bats-jenkins |
| 4 | SUT_CONTAINER=bats-jenkins |
| 5 | |
| 6 | load test_helpers |
| 7 | |
| 8 | @test "build image" { |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 9 | cd $BATS_TEST_DIRNAME/.. |
| 10 | docker build -t $SUT_IMAGE . |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 11 | } |
| 12 | |
| 13 | @test "clean test containers" { |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 14 | cleanup $SUT_CONTAINER |
| 15 | } |
| 16 | |
| 17 | @test "test multiple JENKINS_OPTS" { |
| 18 | # running --help --version should return the version, not the help |
| 19 | local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/ENV JENKINS_VERSION //') |
| 20 | # need the last line of output, removing the last char |
| 21 | local actual_version=$(docker run --rm -ti -e JENKINS_OPTS="--help --version" --name $SUT_CONTAINER -P $SUT_IMAGE | tail -n 1) |
Carlos Sanchez | c24ef82 | 2016-02-29 12:10:31 +0100 | [diff] [blame^] | 22 | assert "${version}" echo "${actual_version::-1}" |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | @test "test jenkins arguments" { |
| 26 | # running --help --version should return the version, not the help |
| 27 | local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/ENV JENKINS_VERSION //') |
| 28 | # need the last line of output, removing the last char |
| 29 | local actual_version=$(docker run --rm -ti --name $SUT_CONTAINER -P $SUT_IMAGE --help --version | tail -n 1) |
Carlos Sanchez | c24ef82 | 2016-02-29 12:10:31 +0100 | [diff] [blame^] | 30 | assert "${version}" echo "${actual_version::-1}" |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | @test "create test container" { |
Carlos Sanchez | c24ef82 | 2016-02-29 12:10:31 +0100 | [diff] [blame^] | 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 |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | @test "test container is running" { |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 38 | sleep 1 # give time to eventually fail to initialize |
| 39 | retry 3 1 assert "true" docker inspect -f {{.State.Running}} $SUT_CONTAINER |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | @test "Jenkins is initialized" { |
| 43 | retry 30 5 test_url /api/json |
| 44 | } |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 45 | |
Carlos Sanchez | c24ef82 | 2016-02-29 12:10:31 +0100 | [diff] [blame^] | 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 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';' \ |
| 49 | bash -c "curl -fsSL $(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 $(get_jenkins_url)/systemInfo | sed 's/<\/tr>/<\/tr>\'$'\n/g' | grep '<td class=\"pane\">user.timezone</td>' | sed -e '${sed_expr}'" |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 52 | } |