spec/inputs/jdbc_spec.rb in logstash-input-jdbc-4.2.1 vs spec/inputs/jdbc_spec.rb in logstash-input-jdbc-4.2.2
- old
+ new
@@ -1,9 +1,11 @@
# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/inputs/jdbc"
require "jdbc/derby"
+require "jdbc/mysql"
+Jdbc::MySQL.load_driver
require "sequel"
require "sequel/adapters/jdbc"
require "timecop"
require "stud/temporary"
require "time"
@@ -24,23 +26,28 @@
let (:db) do
Sequel.connect(mixin_settings['jdbc_connection_string'], :user=> nil, :password=> nil)
end
before :each do
- Jdbc::Derby.load_driver
- db.create_table :test_table do
- DateTime :created_at
- Integer :num
- String :string
- DateTime :custom_time
+ if !RSpec.current_example.metadata[:no_connection]
+ # before body
+ Jdbc::Derby.load_driver
+ db.create_table :test_table do
+ DateTime :created_at
+ Integer :num
+ String :string
+ DateTime :custom_time
+ end
+ db << "CREATE TABLE types_table (num INTEGER, string VARCHAR(255), started_at DATE, custom_time TIMESTAMP, ranking DECIMAL(16,6))"
end
- db << "CREATE TABLE types_table (num INTEGER, string VARCHAR(255), started_at DATE, custom_time TIMESTAMP, ranking DECIMAL(16,6))"
end
after :each do
- db.drop_table(:test_table)
- db.drop_table(:types_table)
+ if !RSpec.current_example.metadata[:no_connection]
+ db.drop_table(:test_table)
+ db.drop_table(:types_table)
+ end
end
context "when registering and tearing down" do
let(:settings) { {"statement" => "SELECT 1 as col1 FROM test_table"} }
@@ -85,10 +92,28 @@
end
let(:config) { mixin_settings.merge(settings) }
end
end
+ context "when connecting to a non-existent server", :no_connection => true do
+ let(:mixin_settings) do
+ super.merge(
+ "jdbc_driver_class" => "com.mysql.jdbc.Driver",
+ "jdbc_connection_string" => "jdbc:mysql://localhost:99999/somedb"
+ )
+ end
+ let(:settings) { super.merge("statement" => "SELECT 1 as col1 FROM test_table", "jdbc_user" => "foo", "jdbc_password" => "bar") }
+
+ it "should not register correctly" do
+ plugin.register
+ q = Queue.new
+ expect do
+ plugin.run(q)
+ end.to raise_error(::Sequel::DatabaseConnectionError)
+ end
+ end
+
context "when both jdbc_password and jdbc_password_filepath arguments are passed" do
let(:statement) { "SELECT * from test_table" }
let(:jdbc_password) { "secret" }
let(:jdbc_password_file_path) { Stud::Temporary.pathname }
let(:settings) { { "jdbc_password_filepath" => jdbc_password_file_path,
@@ -115,10 +140,10 @@
after do
plugin.stop
end
it "should read in jdbc_password from file" do
- expect(plugin.jdbc_password).to eq(jdbc_password)
+ expect(plugin.jdbc_password.value).to eq(jdbc_password)
end
end
context "when neither statement and statement_filepath arguments are passed" do