19
19
require_relative "../../framework/settings"
20
20
require_relative "../../services/logstash_service"
21
21
require_relative "../../framework/helpers"
22
+ require_relative "pluginmanager_spec_helper"
22
23
require "logstash/devutils/rspec/spec_helper"
23
24
require "stud/temporary"
24
25
require "fileutils"
@@ -29,23 +30,32 @@ def gem_in_lock_file?(pattern, lock_file)
29
30
content . match ( pattern )
30
31
end
31
32
33
+ def plugin_filename_re ( name , version )
34
+ %Q(\b #{ Regexp . escape name } -#{ Regexp . escape version } (-java)?\b )
35
+ end
36
+
32
37
# Bundler can mess up installation successful output: https://github.com/elastic/logstash/issues/15801
33
38
INSTALL_SUCCESS_RE = /IB?nstall successful/
34
39
INSTALLATION_SUCCESS_RE = /IB?nstallation successful/
35
40
41
+ INSTALLATION_ABORTED_RE = /Installation aborted/
42
+
36
43
describe "CLI > logstash-plugin install" do
37
- before ( :all ) do
44
+ before ( :each ) do
38
45
@fixture = Fixture . new ( __FILE__ )
39
46
@logstash = @fixture . get_service ( "logstash" )
40
47
@logstash_plugin = @logstash . plugin_cli
41
- @pack_directory = File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , ".." , "fixtures" , "logstash-dummy-pack" ) )
42
48
end
43
49
44
50
shared_examples "install from a pack" do
45
51
let ( :pack ) { "file://#{ File . join ( @pack_directory , "logstash-dummy-pack.zip" ) } " }
46
52
let ( :install_command ) { "bin/logstash-plugin install" }
47
53
let ( :change_dir ) { true }
48
54
55
+ before ( :all ) do
56
+ @pack_directory = File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , ".." , "fixtures" , "logstash-dummy-pack" ) )
57
+ end
58
+
49
59
# When you are on anything by linux we won't disable the internet with seccomp
50
60
if RbConfig ::CONFIG [ "host_os" ] == "linux"
51
61
context "without internet connection (linux seccomp wrapper)" do
@@ -152,4 +162,147 @@ def gem_in_lock_file?(pattern, lock_file)
152
162
end
153
163
end
154
164
end
165
+
166
+ context "rubygems hosted plugin" do
167
+ include_context "pluginmanager validation helpers"
168
+ shared_context ( "install over existing" ) do
169
+ before ( :each ) do
170
+ aggregate_failures ( "precheck" ) do
171
+ expect ( "#{ plugin_name } -#{ existing_plugin_version } " ) . to_not be_installed_gem
172
+ expect ( "#{ plugin_name } " ) . to_not be_installed_gem
173
+ end
174
+ aggregate_failures ( "setup" ) do
175
+ execute = @logstash_plugin . install ( plugin_name , version : existing_plugin_version )
176
+
177
+ expect ( execute . stderr_and_stdout ) . to match ( INSTALLATION_SUCCESS_RE )
178
+ expect ( execute . exit_code ) . to eq ( 0 )
179
+
180
+ expect ( "#{ plugin_name } -#{ existing_plugin_version } " ) . to be_installed_gem
181
+ expect ( plugin_name ) . to be_in_gemfile . with_requirements ( existing_plugin_version )
182
+ end
183
+ end
184
+ end
185
+ shared_examples ( "overwriting existing with explicit version" ) do
186
+ include_context "install over existing"
187
+ it "installs the specified version and removes the pre-existing one" do
188
+ execute = @logstash_plugin . install ( plugin_name , version : specified_plugin_version )
189
+
190
+ aggregate_failures ( "command execution" ) do
191
+ expect ( execute . stderr_and_stdout ) . to match ( INSTALLATION_SUCCESS_RE )
192
+ expect ( execute . exit_code ) . to eq ( 0 )
193
+ end
194
+
195
+ installed = @logstash_plugin . list ( plugin_name , verbose : true )
196
+ expect ( installed . stderr_and_stdout ) . to match ( /#{ Regexp . escape plugin_name } [(]#{ Regexp . escape ( specified_plugin_version ) } [)]/ )
197
+
198
+ expect ( "#{ plugin_name } -#{ existing_plugin_version } " ) . to_not be_installed_gem
199
+ expect ( "#{ plugin_name } -#{ specified_plugin_version } " ) . to be_installed_gem
200
+ end
201
+ end
202
+
203
+ context "when installing over an older version using --version" do
204
+ let ( :plugin_name ) { "logstash-filter-qatest" }
205
+ let ( :existing_plugin_version ) { "0.1.0" }
206
+ let ( :specified_plugin_version ) { "0.1.1" }
207
+
208
+ include_examples "overwriting existing with explicit version"
209
+ end
210
+
211
+ context "when installing over a newer version using --version" do
212
+ let ( :plugin_name ) { "logstash-filter-qatest" }
213
+ let ( :existing_plugin_version ) { "0.1.0" }
214
+ let ( :specified_plugin_version ) { "0.1.1" }
215
+
216
+ include_examples "overwriting existing with explicit version"
217
+ end
218
+
219
+ context "when installing over existing without --version" do
220
+ let ( :plugin_name ) { "logstash-filter-qatest" }
221
+ let ( :existing_plugin_version ) { "0.1.0" }
222
+
223
+ include_context "install over existing"
224
+
225
+ context "with --preserve" do
226
+ it "succeeds without changing the requirements in the Gemfile" do
227
+ execute = @logstash_plugin . install ( plugin_name , preserve : true )
228
+
229
+ aggregate_failures ( "command execution" ) do
230
+ expect ( execute . stderr_and_stdout ) . to match ( INSTALLATION_SUCCESS_RE )
231
+ expect ( execute . exit_code ) . to eq ( 0 )
232
+ end
233
+
234
+ installed = @logstash_plugin . list ( verbose : true )
235
+ expect ( installed . stderr_and_stdout ) . to match ( /#{ Regexp . escape plugin_name } / )
236
+
237
+ # we want to ensure that the act of installing an already-installed plugin
238
+ # does not change its requirements in the gemfile, and leaves the previously-installed
239
+ # version in-tact.
240
+ expect ( plugin_name ) . to be_in_gemfile . with_requirements ( existing_plugin_version )
241
+ expect ( "#{ plugin_name } -#{ existing_plugin_version } " ) . to be_installed_gem
242
+ end
243
+ end
244
+
245
+ context "without --preserve" do
246
+ # this spec is OBSERVED behaviour, which I believe to be undesirable.
247
+ it "succeeds and removes the version requirement from the Gemfile" do
248
+ execute = @logstash_plugin . install ( plugin_name )
249
+
250
+ aggregate_failures ( "command execution" ) do
251
+ expect ( execute . stderr_and_stdout ) . to match ( INSTALLATION_SUCCESS_RE )
252
+ expect ( execute . exit_code ) . to eq ( 0 )
253
+ end
254
+
255
+ installed = @logstash_plugin . list ( plugin_name , verbose : true )
256
+ expect ( installed . stderr_and_stdout ) . to match ( /#{ Regexp . escape plugin_name } / )
257
+
258
+ # This is the potentially-undesirable surprising behaviour, specified here
259
+ # as a means of documentation, not a promise of future behavior.
260
+ expect ( plugin_name ) . to be_in_gemfile . without_requirements
261
+
262
+ # we expect _a_ version of the plugin to be installed, but cannot be opinionated
263
+ # about which version was installed because bundler won't necessarily re-resolve
264
+ # the dependency graph to get us an upgrade since the no-requirements dependency
265
+ # is still met (but it MAY do so if also installing plugins that are not present).
266
+ expect ( "#{ plugin_name } " ) . to be_installed_gem
267
+ end
268
+ end
269
+ end
270
+
271
+ context "installing plugin that isn't present" do
272
+ it "installs the plugin" do
273
+ aggregate_failures ( "prevalidation" ) do
274
+ expect ( "logstash-filter-qatest" ) . to_not be_installed_gem
275
+ end
276
+
277
+ execute = @logstash_plugin . install ( "logstash-filter-qatest" )
278
+
279
+ expect ( execute . stderr_and_stdout ) . to match ( INSTALLATION_SUCCESS_RE )
280
+ expect ( execute . exit_code ) . to eq ( 0 )
281
+
282
+ installed = @logstash_plugin . list ( "logstash-filter-qatest" )
283
+ expect ( installed . stderr_and_stdout ) . to match ( /logstash-filter-qatest/ )
284
+ expect ( installed . exit_code ) . to eq ( 0 )
285
+
286
+ expect ( gem_in_lock_file? ( /logstash-filter-qatest/ , @logstash . lock_file ) ) . to be_truthy
287
+
288
+ expect ( "logstash-filter-qatest" ) . to be_installed_gem
289
+ end
290
+ end
291
+ context "installing plugin that doesn't exist on rubygems" do
292
+ it "doesn't install anything" do
293
+ execute = @logstash_plugin . install ( "logstash-filter-404-no-exist" )
294
+
295
+ expect ( execute . stderr_and_stdout ) . to match ( INSTALLATION_ABORTED_RE )
296
+ expect ( execute . exit_code ) . to eq ( 1 )
297
+ end
298
+ end
299
+ context "installing gem that isn't a plugin" do
300
+ it "doesn't install anything" do
301
+ execute = @logstash_plugin . install ( "dummy_gem" )
302
+
303
+ expect ( execute . stderr_and_stdout ) . to match ( INSTALLATION_ABORTED_RE )
304
+ expect ( execute . exit_code ) . to eq ( 1 )
305
+ end
306
+ end
307
+ end
155
308
end
0 commit comments