blob: e89758cf05956cf82b9f81d12d85a5b41d21c39c [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/..
11 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 Sanchezd01bd512016-07-11 15:42:09 +020018 run bash -c "docker run -ti --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 Sanchezd01bd512016-07-11 15:42:09 +020031 run bash -c "docker run -ti --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
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 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"
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 Sanchez3a83b9d2016-08-08 09:36:28 +020074
75 # Upgrade to new image with different plugins
Vincent Latombebb8f8c92016-07-13 18:18:14 +020076 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}