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 |
Carlos Sanchez | 0c98782 | 2016-03-16 08:42:03 +0100 | [diff] [blame] | 19 | local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/') |
Carlos Sanchez | 2d68b19 | 2016-04-20 13:26:59 +0200 | [diff] [blame] | 20 | # 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 Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | @test "test jenkins arguments" { |
| 25 | # running --help --version should return the version, not the help |
Carlos Sanchez | 0c98782 | 2016-03-16 08:42:03 +0100 | [diff] [blame] | 26 | local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/') |
Carlos Sanchez | 2d68b19 | 2016-04-20 13:26:59 +0200 | [diff] [blame] | 27 | # 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 LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | @test "create test container" { |
Carlos Sanchez | c24ef82 | 2016-02-29 12:10:31 +0100 | [diff] [blame] | 32 | 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] | 33 | } |
| 34 | |
| 35 | @test "test container is running" { |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 36 | sleep 1 # give time to eventually fail to initialize |
| 37 | retry 3 1 assert "true" docker inspect -f {{.State.Running}} $SUT_CONTAINER |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | @test "Jenkins is initialized" { |
| 41 | retry 30 5 test_url /api/json |
| 42 | } |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 43 | |
Carlos Sanchez | c24ef82 | 2016-02-29 12:10:31 +0100 | [diff] [blame] | 44 | @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 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';' \ |
Carlos Sanchez | 5a51d0a | 2016-04-21 13:50:25 +0200 | [diff] [blame] | 47 | 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 Sanchez | c24ef82 | 2016-02-29 12:10:31 +0100 | [diff] [blame] | 48 | assert 'Europe/Madrid' \ |
Carlos Sanchez | 5a51d0a | 2016-04-21 13:50:25 +0200 | [diff] [blame] | 49 | 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 Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 50 | } |
Carlos Sanchez | 177b25f | 2016-02-29 13:53:22 +0100 | [diff] [blame] | 51 | |
Carlos Sanchez | 2d72a18 | 2016-04-20 13:27:15 +0200 | [diff] [blame] | 52 | @test "plugins are installed" { |
Carlos Sanchez | 3e8e948 | 2016-04-20 13:04:48 +0200 | [diff] [blame] | 53 | docker build -t $SUT_IMAGE-plugins $BATS_TEST_DIRNAME/plugins |
Carlos Sanchez | 2d72a18 | 2016-04-20 13:27:15 +0200 | [diff] [blame] | 54 | assert "maven-plugin.jpi maven-plugin.jpi.pinned" docker run -ti --rm $SUT_IMAGE-plugins ls /var/jenkins_home/plugins | sed -e 's/ / /' |
Carlos Sanchez | 3e8e948 | 2016-04-20 13:04:48 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Carlos Sanchez | 177b25f | 2016-02-29 13:53:22 +0100 | [diff] [blame] | 57 | @test "clean test containers" { |
| 58 | cleanup $SUT_CONTAINER |
| 59 | } |