Carlos Sanchez | f7c0eab | 2016-08-14 10:43:48 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env bats |
| 2 | |
| 3 | SUT_IMAGE=bats-jenkins |
| 4 | SUT_CONTAINER=bats-jenkins |
| 5 | |
| 6 | load 'test_helper/bats-support/load' |
| 7 | load 'test_helper/bats-assert/load' |
| 8 | load test_helpers |
| 9 | |
| 10 | @test "build image" { |
| 11 | cd $BATS_TEST_DIRNAME/.. |
| 12 | docker build -t $SUT_IMAGE . |
| 13 | } |
| 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 |
| 23 | assert "${version}" docker run --rm -ti -e JENKINS_OPTS="--help --version" --name $SUT_CONTAINER -P $SUT_IMAGE | tail -n 1 |
| 24 | } |
| 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 |
| 30 | assert "${version}" docker run --rm -ti --name $SUT_CONTAINER -P $SUT_IMAGE --help --version | tail -n 1 |
| 31 | } |
| 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 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';' \ |
| 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 | } |