Skip to content

Commit

Permalink
Covered #build_last_value_tracker with test and verified read and wri…
Browse files Browse the repository at this point in the history
…te action
  • Loading branch information
andsel committed Jun 15, 2023
1 parent 743f919 commit 9a640a7
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions spec/plugin_mixins/jdbc/value_tracking_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: utf-8
require "logstash/plugin_mixins/jdbc/value_tracking"
require "tempfile"

module LogStash module PluginMixins module Jdbc
describe ValueTracking do
Expand Down Expand Up @@ -42,5 +43,71 @@ module LogStash module PluginMixins module Jdbc
end
end
end

context "#build_last_value_tracker" do

let(:plugin) { double("fake plugin") }
let(:temp_file) { Tempfile.new('last_run_tracker') }

before(:each) do
allow(plugin).to receive(:record_last_run).and_return(true)
allow(plugin).to receive(:clean_run).and_return(false)
allow(plugin).to receive(:last_run_metadata_file_path).and_return(temp_file.path)
end

context "create numerical tracker" do
before(:each) do
allow(plugin).to receive(:use_column_value).and_return(true)
allow(plugin).to receive(:tracking_column_type).and_return("numeric")
end

it "should write correctly" do
tracker = ValueTracking.build_last_value_tracker(plugin)
tracker.set_value(1)
tracker.write

temp_file.rewind
v = ValueTracking.load_yaml(::File.read(temp_file.path))
expect(v).to eq 1
end
end

context "create date time tracker" do
before(:each) do
allow(plugin).to receive(:use_column_value).and_return(false)
allow(plugin).to receive(:jdbc_default_timezone).and_return(:something_not_nil)
end

it "should write correctly" do
tracker = ValueTracking.build_last_value_tracker(plugin)
tracker.set_value("2023-06-15T15:28:15+02:00")
tracker.write

temp_file.rewind
v = ValueTracking.load_yaml(::File.read(temp_file.path))
expect(v.class).to eq DateTime
expect(v.year).to eq 2023
end
end

context "create time tracker" do
before(:each) do
allow(plugin).to receive(:use_column_value).and_return(false)
allow(plugin).to receive(:jdbc_default_timezone).and_return(nil)
end

it "should write correctly" do
tracker = ValueTracking.build_last_value_tracker(plugin)
tracker.set_value("2023-06-15T15:28:15+02:00")
tracker.write

temp_file.rewind
v = ValueTracking.load_yaml(::File.read(temp_file.path))
expect(v.class).to eq Time
expect(v.min).to eq 28
end
end

end
end
end end end

0 comments on commit 9a640a7

Please sign in to comment.