Skip to content

Commit 0aa6235

Browse files
committed
Add tzinfo-data and fix tests
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
1 parent 2b439cb commit 0aa6235

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

logstash-input-jdbc.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
2222
s.add_runtime_dependency 'logstash-codec-plain'
2323
s.add_runtime_dependency 'sequel'
2424
s.add_runtime_dependency 'tzinfo'
25+
s.add_runtime_dependency 'tzinfo-data'
2526
s.add_runtime_dependency 'rufus-scheduler'
2627

2728
s.add_development_dependency 'logstash-devutils'

spec/inputs/jdbc_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
require "date"
1010

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

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

258261
context "when fetching time data without jdbc_default_timezone set" do
259-
260262
let(:mixin_settings) do
261263
{ "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
262264
"jdbc_connection_string" => "jdbc:derby:memory:testdb;create=true"
@@ -272,7 +274,6 @@
272274
let(:num_rows) { 1 }
273275

274276
before do
275-
stub_const('ENV', ENV.to_hash.merge('TZ' => 'UTC'))
276277
num_rows.times do
277278
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'))"
278279
end

0 commit comments

Comments
 (0)