Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests related to metadata file moving #136

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/logstash/inputs/jdbc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def ensure_default_metadatafile_location(metadata_new_path)
# the correct access rights
::File.delete(old_default_path.to_path)
@logger.info("Successfully moved the #{old_default_path.to_path} into #{metadata_new_path.to_path}")
rescue e
rescue => e
@logger.warn("Using new metadata file at #{metadata_new_path.to_path} but #{old_default_path} can't be removed.")
end
end
Expand Down
24 changes: 18 additions & 6 deletions spec/inputs/jdbc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1169,19 +1169,31 @@
context "when a file exists" do
before do
# in a faked HOME folder save a valid previous last_run metadata file
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with('HOME').and_return(fake_home)
File.open("#{ENV['HOME']}/.logstash_jdbc_last_run", 'w') do |file|

File.open("#{fake_home}/.logstash_jdbc_last_run", 'w') do |file|
file.write("--- !ruby/object:DateTime '2022-03-08 08:10:00.486889000 Z'")
end
end
let(:old_path) { "#{fake_home}/.logstash_jdbc_last_run" }
let(:path_data) { LogStash::SETTINGS.get_value("path.data") }
let(:new_path) { "#{path_data}/plugins/inputs/jdbc/logstash_jdbc_last_run" }

it "should be moved" do
plugin.register

expect(::File.exist?("#{ENV['HOME']}/.logstash_jdbc_last_run")).to be false
path = LogStash::SETTINGS.get_value("path.data")
full_path = "#{path}/plugins/inputs/jdbc/logstash_jdbc_last_run"
expect(::File.exist?(full_path)).to be true
expect(::File).to_not exist(old_path)
expect(::File).to exist(new_path)
end
context "if the delete fails" do
before(:each) do
allow(File).to receive(:delete).and_raise ArgumentError
end
it "should be still be moved" do
plugin.register
expect(::File).to exist(old_path) # old still exists
expect(::File).to exist(new_path)
end
end
end
end
Expand Down