From 0aa6235fb24dcc6003d6544f9f52220d45d37f5d Mon Sep 17 00:00:00 2001 From: Aaron Mildenstein Date: Wed, 9 Dec 2015 10:58:28 -0700 Subject: [PATCH] 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 --- logstash-input-jdbc.gemspec | 1 + spec/inputs/jdbc_spec.rb | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/logstash-input-jdbc.gemspec b/logstash-input-jdbc.gemspec index 4536872..1a27953 100755 --- a/logstash-input-jdbc.gemspec +++ b/logstash-input-jdbc.gemspec @@ -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' diff --git a/spec/inputs/jdbc_spec.rb b/spec/inputs/jdbc_spec.rb index be1c8ed..06e65c7 100755 --- a/spec/inputs/jdbc_spec.rb +++ b/spec/inputs/jdbc_spec.rb @@ -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"} @@ -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 @@ -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" @@ -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