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/.. |
Carlos Sanchez | 59d9ef6 | 2016-11-09 13:08:41 +0100 | [diff] [blame] | 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 | 3e58be9 | 2016-09-16 18:32:23 -0700 | [diff] [blame] | 18 | run bash -c "docker run --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 | 3e58be9 | 2016-09-16 18:32:23 -0700 | [diff] [blame] | 31 | run bash -c "docker run --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 |
Carlos Sanchez | 3e58be9 | 2016-09-16 18:32:23 -0700 | [diff] [blame] | 57 | run bash -c "docker run --rm $SUT_IMAGE-install-plugins-update unzip -p /var/jenkins_home/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" |
Carlos Sanchez | 3a83b9d | 2016-08-08 09:36:28 +0200 | [diff] [blame] | 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" |
Carlos Sanchez | 3e58be9 | 2016-09-16 18:32:23 -0700 | [diff] [blame] | 67 | mkdir -p $work |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 68 | # Image contains maven-plugin 2.7.1 and ant-plugin 1.3 |
Carlos Sanchez | 3e58be9 | 2016-09-16 18:32:23 -0700 | [diff] [blame] | 69 | run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins true" |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 70 | assert_success |
Carlos Sanchez | 6c3d404 | 2016-12-26 12:37:37 +0100 | [diff] [blame] | 71 | run unzip_manifest maven-plugin.jpi $work |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 72 | assert_line 'Plugin-Version: 2.7.1' |
Carlos Sanchez | 6c3d404 | 2016-12-26 12:37:37 +0100 | [diff] [blame] | 73 | run unzip_manifest ant.jpi $work |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 74 | assert_line 'Plugin-Version: 1.3' |
Carlos Sanchez | 3a83b9d | 2016-08-08 09:36:28 +0200 | [diff] [blame] | 75 | |
| 76 | # Upgrade to new image with different plugins |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 77 | run docker build -t $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins |
| 78 | assert_success |
| 79 | # Images contains maven-plugin 2.13 and ant-plugin 1.2 |
Carlos Sanchez | 3e58be9 | 2016-09-16 18:32:23 -0700 | [diff] [blame] | 80 | run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true" |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 81 | assert_success |
Carlos Sanchez | 6c3d404 | 2016-12-26 12:37:37 +0100 | [diff] [blame] | 82 | run unzip_manifest maven-plugin.jpi $work |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 83 | assert_success |
| 84 | # Should be updated |
| 85 | assert_line 'Plugin-Version: 2.13' |
Carlos Sanchez | 6c3d404 | 2016-12-26 12:37:37 +0100 | [diff] [blame] | 86 | run unzip_manifest ant.jpi $work |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 87 | # 1.2 is older than the existing 1.3, so keep 1.3 |
| 88 | assert_line 'Plugin-Version: 1.3' |
| 89 | } |
| 90 | |
| 91 | @test "clean work directory" { |
| 92 | run bash -c "rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 93 | } |
| 94 | |
| 95 | @test "do not upgrade if plugin has been manually updated" { |
| 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" |
Carlos Sanchez | 3e58be9 | 2016-09-16 18:32:23 -0700 | [diff] [blame] | 99 | mkdir -p $work |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 100 | # Image contains maven-plugin 2.7.1 and ant-plugin 1.3 |
Carlos Sanchez | 21b0f37 | 2016-10-06 13:26:17 -0700 | [diff] [blame] | 101 | run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins curl --connect-timeout 20 --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" |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 102 | assert_success |
Carlos Sanchez | 6c3d404 | 2016-12-26 12:37:37 +0100 | [diff] [blame] | 103 | run unzip_manifest maven-plugin.jpi $work |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 104 | assert_line 'Plugin-Version: 2.12.1' |
| 105 | run docker build -t $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins |
| 106 | assert_success |
| 107 | # Images contains maven-plugin 2.13 and ant-plugin 1.2 |
Carlos Sanchez | 3e58be9 | 2016-09-16 18:32:23 -0700 | [diff] [blame] | 108 | run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true" |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 109 | assert_success |
Carlos Sanchez | 6c3d404 | 2016-12-26 12:37:37 +0100 | [diff] [blame] | 110 | run unzip_manifest maven-plugin.jpi $work |
Vincent Latombe | bb8f8c9 | 2016-07-13 18:18:14 +0200 | [diff] [blame] | 111 | assert_success |
| 112 | # Shouldn't be updated |
| 113 | refute_line 'Plugin-Version: 2.13' |
| 114 | } |
| 115 | |
| 116 | @test "clean work directory" { |
| 117 | run bash -c "rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work" |
| 118 | } |