blob: d795f233b47f34cdc7d0a926654f1e8ecaa7532c [file] [log] [blame]
Thomas LEVEIL58695bb2015-09-04 21:51:10 +00001#!/usr/bin/env bats
2
3SUT_IMAGE=bats-jenkins
Thomas LEVEIL58695bb2015-09-04 21:51:10 +00004
Carlos Sanchez67055a22016-06-27 17:08:15 +02005load 'test_helper/bats-support/load'
6load 'test_helper/bats-assert/load'
Thomas LEVEIL58695bb2015-09-04 21:51:10 +00007load test_helpers
8
9@test "build image" {
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010010 cd $BATS_TEST_DIRNAME/..
Carlos Sanchez59d9ef62016-11-09 13:08:41 +010011 docker_build -t $SUT_IMAGE .
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000012}
13
Carlos Sanchez67055a22016-06-27 17:08:15 +020014@test "plugins are installed with plugins.sh" {
Carlos Sanchez45a62852016-06-27 23:28:48 +020015 run docker build -t $SUT_IMAGE-plugins $BATS_TEST_DIRNAME/plugins
Carlos Sanchez67055a22016-06-27 17:08:15 +020016 assert_success
17 # replace DOS line endings \r\n
Carlos Sanchez3e58be92016-09-16 18:32:23 -070018 run bash -c "docker run --rm $SUT_IMAGE-plugins ls --color=never -1 /var/jenkins_home/plugins | tr -d '\r'"
Carlos Sanchez67055a22016-06-27 17:08:15 +020019 assert_success
Carlos Sanchez1bcbb382016-08-05 11:38:53 +020020 assert_line 'maven-plugin.jpi'
21 assert_line 'maven-plugin.jpi.pinned'
Carlos Sanchez45a62852016-06-27 23:28:48 +020022 assert_line 'ant.jpi'
23 assert_line 'ant.jpi.pinned'
Carlos Sanchez67055a22016-06-27 17:08:15 +020024}
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 Sanchez0ab40702016-08-05 10:44:58 +020029 refute_line --partial 'Skipping already bundled dependency'
Carlos Sanchez67055a22016-06-27 17:08:15 +020030 # replace DOS line endings \r\n
Carlos Sanchez3e58be92016-09-16 18:32:23 -070031 run bash -c "docker run --rm $SUT_IMAGE-install-plugins ls --color=never -1 /var/jenkins_home/plugins | tr -d '\r'"
Carlos Sanchez67055a22016-06-27 17:08:15 +020032 assert_success
33 assert_line 'maven-plugin.jpi'
34 assert_line 'maven-plugin.jpi.pinned'
Carlos Sanchez45a62852016-06-27 23:28:48 +020035 assert_line 'ant.jpi'
36 assert_line 'ant.jpi.pinned'
Carlos Sanchez82272772016-07-18 09:58:29 +020037 assert_line 'credentials.jpi'
38 assert_line 'credentials.jpi.pinned'
39 assert_line 'mesos.jpi'
40 assert_line 'mesos.jpi.pinned'
Carlos Sanchez0ab40702016-08-05 10:44:58 +020041 # optional dependencies
Carlos Sanchez04473ff2016-07-19 13:19:51 +020042 refute_line 'metrics.jpi'
43 refute_line 'metrics.jpi.pinned'
Carlos Sanchez0ab40702016-08-05 10:44:58 +020044 # 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 Sanchez3e8e9482016-04-20 13:04:48 +020049}
50
Carlos Sanchez3a83b9d2016-08-08 09:36:28 +020051@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 Sanchez3e58be92016-09-16 18:32:23 -070057 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 Sanchez3a83b9d2016-08-08 09:36:28 +020058 assert_success
59 assert_line 'Plugin-Version: 2.13'
60}
61
Vincent Latombebb8f8c92016-07-13 18:18:14 +020062@test "plugins are getting upgraded but not downgraded" {
Carlos Sanchez3a83b9d2016-08-08 09:36:28 +020063 # Initial execution
Vincent Latombebb8f8c92016-07-13 18:18:14 +020064 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 Sanchez3e58be92016-09-16 18:32:23 -070067 mkdir -p $work
Vincent Latombebb8f8c92016-07-13 18:18:14 +020068 # Image contains maven-plugin 2.7.1 and ant-plugin 1.3
Carlos Sanchez3e58be92016-09-16 18:32:23 -070069 run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins true"
Vincent Latombebb8f8c92016-07-13 18:18:14 +020070 assert_success
Carlos Sanchez6c3d4042016-12-26 12:37:37 +010071 run unzip_manifest maven-plugin.jpi $work
Vincent Latombebb8f8c92016-07-13 18:18:14 +020072 assert_line 'Plugin-Version: 2.7.1'
Carlos Sanchez6c3d4042016-12-26 12:37:37 +010073 run unzip_manifest ant.jpi $work
Vincent Latombebb8f8c92016-07-13 18:18:14 +020074 assert_line 'Plugin-Version: 1.3'
Carlos Sanchez3a83b9d2016-08-08 09:36:28 +020075
76 # Upgrade to new image with different plugins
Vincent Latombebb8f8c92016-07-13 18:18:14 +020077 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 Sanchez3e58be92016-09-16 18:32:23 -070080 run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true"
Vincent Latombebb8f8c92016-07-13 18:18:14 +020081 assert_success
Carlos Sanchez6c3d4042016-12-26 12:37:37 +010082 run unzip_manifest maven-plugin.jpi $work
Vincent Latombebb8f8c92016-07-13 18:18:14 +020083 assert_success
84 # Should be updated
85 assert_line 'Plugin-Version: 2.13'
Carlos Sanchez6c3d4042016-12-26 12:37:37 +010086 run unzip_manifest ant.jpi $work
Vincent Latombebb8f8c92016-07-13 18:18:14 +020087 # 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 Sanchez3e58be92016-09-16 18:32:23 -070099 mkdir -p $work
Vincent Latombebb8f8c92016-07-13 18:18:14 +0200100 # Image contains maven-plugin 2.7.1 and ant-plugin 1.3
Carlos Sanchez21b0f372016-10-06 13:26:17 -0700101 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 Latombebb8f8c92016-07-13 18:18:14 +0200102 assert_success
Carlos Sanchez6c3d4042016-12-26 12:37:37 +0100103 run unzip_manifest maven-plugin.jpi $work
Vincent Latombebb8f8c92016-07-13 18:18:14 +0200104 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 Sanchez3e58be92016-09-16 18:32:23 -0700108 run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true"
Vincent Latombebb8f8c92016-07-13 18:18:14 +0200109 assert_success
Carlos Sanchez6c3d4042016-12-26 12:37:37 +0100110 run unzip_manifest maven-plugin.jpi $work
Vincent Latombebb8f8c92016-07-13 18:18:14 +0200111 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}