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 | |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 6 | load 'test_helper/bats-support/load' |
| 7 | load 'test_helper/bats-assert/load' |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 8 | load test_helpers |
| 9 | |
| 10 | @test "build image" { |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 11 | cd $BATS_TEST_DIRNAME/.. |
| 12 | docker build -t $SUT_IMAGE . |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | @test "clean test containers" { |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 16 | cleanup $SUT_CONTAINER |
| 17 | } |
| 18 | |
| 19 | @test "test multiple JENKINS_OPTS" { |
| 20 | # running --help --version should return the version, not the help |
Carlos Sanchez | 0c98782 | 2016-03-16 08:42:03 +0100 | [diff] [blame] | 21 | local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/') |
Carlos Sanchez | 2d68b19 | 2016-04-20 13:26:59 +0200 | [diff] [blame] | 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 |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | @test "test jenkins arguments" { |
| 27 | # running --help --version should return the version, not the help |
Carlos Sanchez | 0c98782 | 2016-03-16 08:42:03 +0100 | [diff] [blame] | 28 | local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/') |
Carlos Sanchez | 2d68b19 | 2016-04-20 13:26:59 +0200 | [diff] [blame] | 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 |
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';' \ |
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\">hudson.model.DirectoryBrowserSupport.CSP</td>' | sed -e '${sed_expr}'" |
Carlos Sanchez | c24ef82 | 2016-02-29 12:10:31 +0100 | [diff] [blame] | 50 | assert 'Europe/Madrid' \ |
Carlos Sanchez | 5a51d0a | 2016-04-21 13:50:25 +0200 | [diff] [blame] | 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}'" |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 52 | } |
Carlos Sanchez | 177b25f | 2016-02-29 13:53:22 +0100 | [diff] [blame] | 53 | |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 54 | @test "plugins are installed with plugins.sh" { |
Carlos Sanchez | 45a6285 | 2016-06-27 23:28:48 +0200 | [diff] [blame] | 55 | run docker build -t $SUT_IMAGE-plugins $BATS_TEST_DIRNAME/plugins |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 56 | assert_success |
| 57 | # replace DOS line endings \r\n |
Carlos Sanchez | d01bd51 | 2016-07-11 15:42:09 +0200 | [diff] [blame] | 58 | run bash -c "docker run -ti --rm $SUT_IMAGE-plugins ls --color=never -1 /var/jenkins_home/plugins | tr -d '\r'" |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 59 | assert_success |
Carlos Sanchez | 1bcbb38 | 2016-08-05 11:38:53 +0200 | [diff] [blame^] | 60 | assert_line 'maven-plugin.jpi' |
| 61 | assert_line 'maven-plugin.jpi.pinned' |
Carlos Sanchez | 45a6285 | 2016-06-27 23:28:48 +0200 | [diff] [blame] | 62 | assert_line 'ant.jpi' |
| 63 | assert_line 'ant.jpi.pinned' |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @test "plugins are installed with install-plugins.sh" { |
| 67 | run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins |
| 68 | assert_success |
Carlos Sanchez | 0ab4070 | 2016-08-05 10:44:58 +0200 | [diff] [blame] | 69 | refute_line --partial 'Skipping already bundled dependency' |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 70 | # replace DOS line endings \r\n |
Carlos Sanchez | d01bd51 | 2016-07-11 15:42:09 +0200 | [diff] [blame] | 71 | run bash -c "docker run -ti --rm $SUT_IMAGE-install-plugins ls --color=never -1 /var/jenkins_home/plugins | tr -d '\r'" |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 72 | assert_success |
| 73 | assert_line 'maven-plugin.jpi' |
| 74 | assert_line 'maven-plugin.jpi.pinned' |
Carlos Sanchez | 45a6285 | 2016-06-27 23:28:48 +0200 | [diff] [blame] | 75 | assert_line 'ant.jpi' |
| 76 | assert_line 'ant.jpi.pinned' |
Carlos Sanchez | 8227277 | 2016-07-18 09:58:29 +0200 | [diff] [blame] | 77 | assert_line 'credentials.jpi' |
| 78 | assert_line 'credentials.jpi.pinned' |
| 79 | assert_line 'mesos.jpi' |
| 80 | assert_line 'mesos.jpi.pinned' |
Carlos Sanchez | 0ab4070 | 2016-08-05 10:44:58 +0200 | [diff] [blame] | 81 | # optional dependencies |
Carlos Sanchez | 04473ff | 2016-07-19 13:19:51 +0200 | [diff] [blame] | 82 | refute_line 'metrics.jpi' |
| 83 | refute_line 'metrics.jpi.pinned' |
Carlos Sanchez | 0ab4070 | 2016-08-05 10:44:58 +0200 | [diff] [blame] | 84 | # plugins bundled but under detached-plugins, so need to be installed |
| 85 | assert_line 'javadoc.jpi' |
| 86 | assert_line 'javadoc.jpi.pinned' |
| 87 | assert_line 'mailer.jpi' |
| 88 | assert_line 'mailer.jpi.pinned' |
Carlos Sanchez | 3e8e948 | 2016-04-20 13:04:48 +0200 | [diff] [blame] | 89 | } |
| 90 | |
Carlos Sanchez | 177b25f | 2016-02-29 13:53:22 +0100 | [diff] [blame] | 91 | @test "clean test containers" { |
| 92 | cleanup $SUT_CONTAINER |
| 93 | } |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 94 | |
| 95 | @test "plugins are getting upgraded but not downgraded" { |
| 96 | run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins |
| 97 | assert_success |
| 98 | local work; work="$BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 99 | # Image contains maven-plugin 2.7.1 and ant-plugin 1.3 |
| 100 | run bash -c "docker run -ti -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins true" |
| 101 | assert_success |
| 102 | run bash -c "unzip -p $work/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 103 | assert_line 'Plugin-Version: 2.7.1' |
| 104 | run bash -c "unzip -p $work/plugins/ant.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 105 | assert_line 'Plugin-Version: 1.3' |
| 106 | run docker build -t $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins |
| 107 | assert_success |
| 108 | # Images contains maven-plugin 2.13 and ant-plugin 1.2 |
| 109 | run bash -c "docker run -ti -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true" |
| 110 | assert_success |
| 111 | run bash -c "unzip -p $work/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 112 | assert_success |
| 113 | # Should be updated |
| 114 | assert_line 'Plugin-Version: 2.13' |
| 115 | run bash -c "unzip -p $work/plugins/ant.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 116 | # 1.2 is older than the existing 1.3, so keep 1.3 |
| 117 | assert_line 'Plugin-Version: 1.3' |
| 118 | } |
| 119 | |
| 120 | @test "clean work directory" { |
| 121 | run bash -c "rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 122 | } |
| 123 | |
| 124 | @test "do not upgrade if plugin has been manually updated" { |
| 125 | run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins |
| 126 | assert_success |
| 127 | local work; work="$BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 128 | # Image contains maven-plugin 2.7.1 and ant-plugin 1.3 |
| 129 | run bash -c "docker run -ti -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins curl --connect-timeout 5 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L https://updates.jenkins.io/download/plugins/maven-plugin/2.12.1/maven-plugin.hpi -o /var/jenkins_home/plugins/maven-plugin.jpi" |
| 130 | assert_success |
| 131 | run bash -c "unzip -p $work/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 132 | assert_line 'Plugin-Version: 2.12.1' |
| 133 | run docker build -t $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins |
| 134 | assert_success |
| 135 | # Images contains maven-plugin 2.13 and ant-plugin 1.2 |
| 136 | run bash -c "docker run -ti -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true" |
| 137 | assert_success |
| 138 | run bash -c "unzip -p $work/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 139 | assert_success |
| 140 | # Shouldn't be updated |
| 141 | refute_line 'Plugin-Version: 2.13' |
| 142 | } |
| 143 | |
| 144 | @test "clean work directory" { |
| 145 | run bash -c "rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 146 | } |