-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathinteg_spec.rb
80 lines (68 loc) · 2.37 KB
/
integ_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require "logstash/devutils/rspec/spec_helper"
require "logstash/devutils/rspec/shared_examples"
require "logstash/inputs/jdbc"
require "sequel"
require "sequel/adapters/jdbc"
# This test requires: Firebird installed to Mac OSX, it uses the built-in example database `employee`
describe LogStash::Inputs::Jdbc, :integration => true 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"
# For Travis and CI based on docker, we source from ENV
jdbc_connection_string = ENV.fetch("PG_CONNECTION_STRING",
"jdbc:postgresql://postgresql:5432") + "/jdbc_input_db?user=postgres"
let(:settings) do
{ "jdbc_driver_class" => "org.postgresql.Driver",
"jdbc_connection_string" => jdbc_connection_string,
"jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
"jdbc_user" => "postgres",
"jdbc_password" => ENV["POSTGRES_PASSWORD"],
"statement" => 'SELECT FIRST_NAME, LAST_NAME FROM "employee" WHERE EMP_NO = 2'
}
end
let(:plugin) { LogStash::Inputs::Jdbc.new(settings) }
let(:queue) { Queue.new }
context "when connecting to a postgres instance" do
before do
plugin.register
end
after do
plugin.stop
end
it "should populate the event with database entries" do
plugin.run(queue)
event = queue.pop
expect(event.get('first_name')).to eq("Mark")
expect(event.get('last_name')).to eq("Guckenheimer")
end
end
context "when supplying a non-existent library" do
let(:settings) do
super().merge(
"jdbc_driver_library" => "/no/path/to/postgresql.jar"
)
end
it "should not register correctly" do
plugin.register
q = Queue.new
expect do
plugin.run(q)
end.to raise_error(::LogStash::PluginLoadingError)
end
end
context "when connecting to a non-existent server" do
let(:settings) do
super().merge(
"jdbc_connection_string" => "jdbc:postgresql://localhost:65000/somedb"
)
end
it "should not register correctly" do
plugin.register
q = Queue.new
expect do
plugin.run(q)
end.to raise_error(::Sequel::DatabaseConnectionError)
end
end
end