Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bats |
| 2 | |
| 3 | SUT_IMAGE=bats-jenkins |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 4 | |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 5 | load 'test_helper/bats-support/load' |
| 6 | load 'test_helper/bats-assert/load' |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 7 | load test_helpers |
| 8 | |
| 9 | @test "build image" { |
Carlos Sanchez | 5fc9cd0 | 2016-02-28 15:25:18 +0100 | [diff] [blame] | 10 | cd $BATS_TEST_DIRNAME/.. |
| 11 | docker build -t $SUT_IMAGE . |
Thomas LEVEIL | 58695bb | 2015-09-04 21:51:10 +0000 | [diff] [blame] | 12 | } |
| 13 | |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 14 | @test "plugins are installed with plugins.sh" { |
Carlos Sanchez | 45a6285 | 2016-06-27 23:28:48 +0200 | [diff] [blame] | 15 | run docker build -t $SUT_IMAGE-plugins $BATS_TEST_DIRNAME/plugins |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 16 | assert_success |
| 17 | # replace DOS line endings \r\n |
Carlos Sanchez | d01bd51 | 2016-07-11 15:42:09 +0200 | [diff] [blame] | 18 | 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] | 19 | assert_success |
Carlos Sanchez | 1bcbb38 | 2016-08-05 11:38:53 +0200 | [diff] [blame] | 20 | assert_line 'maven-plugin.jpi' |
| 21 | assert_line 'maven-plugin.jpi.pinned' |
Carlos Sanchez | 45a6285 | 2016-06-27 23:28:48 +0200 | [diff] [blame] | 22 | assert_line 'ant.jpi' |
| 23 | assert_line 'ant.jpi.pinned' |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | @test "plugins are installed with install-plugins.sh" { |
| 27 | run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins |
| 28 | assert_success |
Carlos Sanchez | 0ab4070 | 2016-08-05 10:44:58 +0200 | [diff] [blame] | 29 | refute_line --partial 'Skipping already bundled dependency' |
Carlos Sanchez | 67055a2 | 2016-06-27 17:08:15 +0200 | [diff] [blame] | 30 | # replace DOS line endings \r\n |
Carlos Sanchez | d01bd51 | 2016-07-11 15:42:09 +0200 | [diff] [blame] | 31 | 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] | 32 | assert_success |
| 33 | assert_line 'maven-plugin.jpi' |
| 34 | assert_line 'maven-plugin.jpi.pinned' |
Carlos Sanchez | 45a6285 | 2016-06-27 23:28:48 +0200 | [diff] [blame] | 35 | assert_line 'ant.jpi' |
| 36 | assert_line 'ant.jpi.pinned' |
Carlos Sanchez | 8227277 | 2016-07-18 09:58:29 +0200 | [diff] [blame] | 37 | assert_line 'credentials.jpi' |
| 38 | assert_line 'credentials.jpi.pinned' |
| 39 | assert_line 'mesos.jpi' |
| 40 | assert_line 'mesos.jpi.pinned' |
Carlos Sanchez | 0ab4070 | 2016-08-05 10:44:58 +0200 | [diff] [blame] | 41 | # optional dependencies |
Carlos Sanchez | 04473ff | 2016-07-19 13:19:51 +0200 | [diff] [blame] | 42 | refute_line 'metrics.jpi' |
| 43 | refute_line 'metrics.jpi.pinned' |
Carlos Sanchez | 0ab4070 | 2016-08-05 10:44:58 +0200 | [diff] [blame] | 44 | # plugins bundled but under detached-plugins, so need to be installed |
| 45 | assert_line 'javadoc.jpi' |
| 46 | assert_line 'javadoc.jpi.pinned' |
| 47 | assert_line 'mailer.jpi' |
| 48 | assert_line 'mailer.jpi.pinned' |
Carlos Sanchez | 3e8e948 | 2016-04-20 13:04:48 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Carlos Sanchez | 3a83b9d | 2016-08-08 09:36:28 +0200 | [diff] [blame] | 51 | @test "plugins are installed with install-plugins.sh even when already exist" { |
| 52 | run docker build -t $SUT_IMAGE-install-plugins-update --no-cache $BATS_TEST_DIRNAME/install-plugins/update |
| 53 | assert_success |
| 54 | assert_line "Using provided plugin: ant" |
| 55 | refute_line --partial 'Skipping already bundled dependency' |
| 56 | # replace DOS line endings \r\n |
| 57 | run bash -c "docker run -ti --rm $SUT_IMAGE-install-plugins-update unzip -p /var/jenkins_home/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 58 | assert_success |
| 59 | assert_line 'Plugin-Version: 2.13' |
| 60 | } |
| 61 | |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 62 | @test "plugins are getting upgraded but not downgraded" { |
Carlos Sanchez | 3a83b9d | 2016-08-08 09:36:28 +0200 | [diff] [blame] | 63 | # Initial execution |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 64 | run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins |
| 65 | assert_success |
| 66 | local work; work="$BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 67 | # Image contains maven-plugin 2.7.1 and ant-plugin 1.3 |
| 68 | run bash -c "docker run -ti -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins true" |
| 69 | assert_success |
| 70 | run bash -c "unzip -p $work/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 71 | assert_line 'Plugin-Version: 2.7.1' |
| 72 | run bash -c "unzip -p $work/plugins/ant.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 73 | assert_line 'Plugin-Version: 1.3' |
Carlos Sanchez | 3a83b9d | 2016-08-08 09:36:28 +0200 | [diff] [blame] | 74 | |
| 75 | # Upgrade to new image with different plugins |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 76 | run docker build -t $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins |
| 77 | assert_success |
| 78 | # Images contains maven-plugin 2.13 and ant-plugin 1.2 |
| 79 | run bash -c "docker run -ti -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true" |
| 80 | assert_success |
| 81 | run bash -c "unzip -p $work/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 82 | assert_success |
| 83 | # Should be updated |
| 84 | assert_line 'Plugin-Version: 2.13' |
| 85 | run bash -c "unzip -p $work/plugins/ant.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 86 | # 1.2 is older than the existing 1.3, so keep 1.3 |
| 87 | assert_line 'Plugin-Version: 1.3' |
| 88 | } |
| 89 | |
| 90 | @test "clean work directory" { |
| 91 | run bash -c "rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 92 | } |
| 93 | |
| 94 | @test "do not upgrade if plugin has been manually updated" { |
| 95 | run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins |
| 96 | assert_success |
| 97 | local work; work="$BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 98 | # Image contains maven-plugin 2.7.1 and ant-plugin 1.3 |
| 99 | 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" |
| 100 | assert_success |
| 101 | run bash -c "unzip -p $work/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 102 | assert_line 'Plugin-Version: 2.12.1' |
| 103 | run docker build -t $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins |
| 104 | assert_success |
| 105 | # Images contains maven-plugin 2.13 and ant-plugin 1.2 |
| 106 | run bash -c "docker run -ti -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true" |
| 107 | assert_success |
| 108 | run bash -c "unzip -p $work/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
| 109 | assert_success |
| 110 | # Shouldn't be updated |
| 111 | refute_line 'Plugin-Version: 2.13' |
| 112 | } |
| 113 | |
| 114 | @test "clean work directory" { |
| 115 | run bash -c "rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 116 | } |