Skip to content

Commit

Permalink
Add tzinfo-data and fix tests
Browse files Browse the repository at this point in the history
The previous attempt to use stub_const did not "unset" between runs.
It is simpler to hard-code a timezone for all tests, to guarantee
that there are no ambiguities.

Because SQL timestamps do not allow for timezone or offset data, this
should not be a limiting factor for the tests.

Fixes #97
  • Loading branch information
untergeek committed Dec 9, 2015
1 parent 2b439cb commit 0aa6235
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions logstash-input-jdbc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'logstash-codec-plain'
s.add_runtime_dependency 'sequel'
s.add_runtime_dependency 'tzinfo'
s.add_runtime_dependency 'tzinfo-data'
s.add_runtime_dependency 'rufus-scheduler'

s.add_development_dependency 'logstash-devutils'
Expand Down
7 changes: 4 additions & 3 deletions spec/inputs/jdbc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
require "date"

describe LogStash::Inputs::Jdbc do
# This is a necessary change test-wide to guarantee that no local timezone
# is picked up. It could be arbitrarily set to any timezone, but then the test
# would have to compensate differently. That's why UTC is chosen.
ENV["TZ"] = "Etc/UTC"
let(:mixin_settings) do
{ "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
"jdbc_connection_string" => "jdbc:derby:memory:testdb;create=true"}
Expand Down Expand Up @@ -235,7 +239,6 @@
let(:num_rows) { 10 }

before do
stub_const('ENV', ENV.to_hash.merge('TZ' => 'UTC'))
num_rows.times do
db[:test_table].insert(:num => 1, :custom_time => "2015-01-01 12:00:00", :created_at => Time.now.utc)
end
Expand All @@ -256,7 +259,6 @@
end

context "when fetching time data without jdbc_default_timezone set" do

let(:mixin_settings) do
{ "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
"jdbc_connection_string" => "jdbc:derby:memory:testdb;create=true"
Expand All @@ -272,7 +274,6 @@
let(:num_rows) { 1 }

before do
stub_const('ENV', ENV.to_hash.merge('TZ' => 'UTC'))
num_rows.times do
db.run "INSERT INTO test_table (created_at, num, custom_time) VALUES (TIMESTAMP('2015-01-01 12:00:00'), 1, TIMESTAMP('2015-01-01 12:00:00'))"
end
Expand Down

0 comments on commit 0aa6235

Please sign in to comment.