spec/inputs/jdbc_spec.rb in logstash-input-jdbc-2.0.4 vs spec/inputs/jdbc_spec.rb in logstash-input-jdbc-2.0.5
- old
+ new
@@ -17,11 +17,12 @@
before :each do
Jdbc::Derby.load_driver
db.create_table :test_table do
DateTime :created_at
- Integer :num
+ Integer :num
+ DateTime :custom_time
end
end
after :each do
db.drop_table(:test_table)
@@ -94,11 +95,11 @@
context "when passing parameters" do
let(:settings) do
{
"statement" => "SELECT :num_param as num_param FROM SYSIBM.SYSDUMMY1",
- "parameters" => {"num_param" => 10}
+ "parameters" => { "num_param" => 10}
}
end
before do
plugin.register
@@ -157,20 +158,49 @@
plugin.stop
end
it "should fetch all rows" do
num_rows.times do
- db[:test_table].insert(:num => 1, :created_at => Time.now.utc)
+ db[:test_table].insert(:num => 1, :custom_time => Time.now.utc, :created_at => Time.now.utc)
end
plugin.run(queue)
expect(queue.size).to eq(num_rows)
end
end
+ context "when fetching time data" do
+
+ let(:settings) do
+ {
+ "statement" => "SELECT * from test_table",
+ }
+ end
+
+ let(:num_rows) { 10 }
+
+ before do
+ num_rows.times do
+ db[:test_table].insert(:num => 1, :custom_time => Time.now.utc, :created_at => Time.now.utc)
+ end
+
+ plugin.register
+ end
+
+ after do
+ plugin.stop
+ end
+
+ it "should convert it to LogStash::Timestamp " do
+ plugin.run(queue)
+ event = queue.pop
+ expect(event["custom_time"]).to be_a(LogStash::Timestamp)
+ end
+ end
+
context "when iteratively running plugin#run" do
let(:settings) do
{"statement" => "SELECT num, created_at FROM test_table WHERE created_at > :sql_last_start"}
end
@@ -287,10 +317,10 @@
let(:num_rows) { 10 }
before do
num_rows.times do
- db[:test_table].insert(:num => 1, :created_at => Time.now.utc)
+ db[:test_table].insert(:num => 1, :custom_time => Time.now.utc, :created_at => Time.now.utc)
end
plugin.register
end