avoid clashes between Environment class methods

Fixes #10860
This commit is contained in:
Joao Duarte 2019-06-14 17:49:25 +01:00 committed by João Duarte
parent a1e806d2c5
commit f18992c647
5 changed files with 15 additions and 11 deletions

View file

@ -42,7 +42,7 @@ module LogStash
!File.exists?(File.join(LogStash::Environment::LOGSTASH_HOME, "x-pack"))
end
def windows?
def win_platform?
::Gem.win_platform?
end

View file

@ -2,8 +2,8 @@
require_relative "pack_command"
class LogStash::PluginManager::Pack < LogStash::PluginManager::PackCommand
option "--tgz", :flag, "compress package as a tar.gz file", :default => !LogStash::Environment.windows?
option "--zip", :flag, "compress package as a zip file", :default => LogStash::Environment.windows?
option "--tgz", :flag, "compress package as a tar.gz file", :default => !LogStash::Environment.win_platform?
option "--zip", :flag, "compress package as a zip file", :default => LogStash::Environment.win_platform?
option "--[no-]clean", :flag, "clean up the generated dump of plugins", :default => true
option "--overwrite", :flag, "Overwrite a previously generated package file", :default => false

View file

@ -2,8 +2,8 @@
require_relative "pack_command"
class LogStash::PluginManager::Unpack < LogStash::PluginManager::PackCommand
option "--tgz", :flag, "unpack a packaged tar.gz file", :default => !LogStash::Environment.windows?
option "--zip", :flag, "unpack a packaged zip file", :default => LogStash::Environment.windows?
option "--tgz", :flag, "unpack a packaged tar.gz file", :default => !LogStash::Environment.win_platform?
option "--zip", :flag, "unpack a packaged zip file", :default => LogStash::Environment.win_platform?
parameter "file", "the package file name", :attribute_name => :package_file, :required => true

View file

@ -164,11 +164,15 @@ module LogStash
end
def windows?
RbConfig::CONFIG['host_os'] =~ WINDOW_OS_RE
host_os =~ WINDOW_OS_RE
end
def linux?
RbConfig::CONFIG['host_os'] =~ LINUX_OS_RE
host_os =~ LINUX_OS_RE
end
def host_os
RbConfig::CONFIG['host_os']
end
def locales_path(path)

View file

@ -57,14 +57,14 @@ describe LogStash::Environment do
context "windows" do
windows_host_os.each do |host|
it "#{host} returns true" do
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
allow(LogStash::Environment).to receive(:host_os).and_return(host)
expect(LogStash::Environment.windows?).to be_truthy
end
end
linux_host_os.each do |host|
it "#{host} returns false" do
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
allow(LogStash::Environment).to receive(:host_os).and_return(host)
expect(LogStash::Environment.windows?).to be_falsey
end
end
@ -73,14 +73,14 @@ describe LogStash::Environment do
context "Linux" do
windows_host_os.each do |host|
it "#{host} returns true" do
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
allow(LogStash::Environment).to receive(:host_os).and_return(host)
expect(LogStash::Environment.linux?).to be_falsey
end
end
linux_host_os.each do |host|
it "#{host} returns false" do
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
allow(LogStash::Environment).to receive(:host_os).and_return(host)
expect(LogStash::Environment.linux?).to be_truthy
end
end