spec/inputs/relp_spec.rb in logstash-input-relp-0.1.5 vs spec/inputs/relp_spec.rb in logstash-input-relp-2.0.1
- old
+ new
@@ -1,60 +1,113 @@
-# coding: utf-8
-require "logstash/devutils/rspec/spec_helper"
-require "socket"
-require "logstash/util/relp"
+# encoding: utf-8
+require_relative "../spec_helper"
+require_relative "../support/ssl"
-describe "inputs/relp" do
+describe LogStash::Inputs::Relp do
- it "should do single client connection" do
- event_count = 10
- port = 5511
- conf = <<-CONFIG
- input {
- relp {
- type => "blah"
- port => #{port}
- }
- }
- CONFIG
+ before do
+ srand(RSpec.configuration.seed)
+ end
- events = input(conf) do |pipeline, queue|
- client = RelpClient.new("0.0.0.0", port, ["syslog"])
- event_count.times do |value|
- client.syslog_write("Hello #{value}")
+ describe "registration and close" do
+
+ it "should register without errors" do
+ input = LogStash::Plugin.lookup("input", "relp").new("port" => 1234)
+ expect {input.register}.to_not raise_error
+ end
+
+ end
+
+ describe "when interrupting the plugin" do
+
+ let(:port) { rand(1024..65532) }
+
+ it_behaves_like "an interruptible input plugin" do
+ let(:config) { { "port" => port } }
+ end
+ end
+
+ describe "multiple client connections" do
+
+ let(:nclients) { rand(200) }
+ let(:nevents) { 100 }
+ let(:port) { 5512 }
+
+ let(:conf) do
+ <<-CONFIG
+ input {
+ relp {
+ type => "blah"
+ port => #{port}
+ }
+ }
+ CONFIG
+ end
+
+ let(:clients) { setup_clients(nclients, port) }
+
+ let(:events) do
+ input(conf, (nevents*nclients)) do
+ nevents.times do |value|
+ clients.each_with_index do |client, index|
+ client.syslog_write("Hello from client#{index}")
+ end
+ end
end
- event_count.times.collect { queue.pop }
end
- event_count.times do |i|
- insist { events[i]["message"] } == "Hello #{i}"
+ it "should do multiple connections" do
+ nclients.times do |client_id|
+ expect(events).to have(nevents).with("Hello from client#{client_id}")
+ end
end
end
- it "should do two client connection" do
- event_count = 100
- port = 5512
- conf = <<-CONFIG
- input {
- relp {
- type => "blah"
- port => #{port}
- }
- }
- CONFIG
+ describe "SSL support" do
- events = input(conf) do |pipeline, queue|
- client = RelpClient.new("0.0.0.0", port, ["syslog"])
- client2 = RelpClient.new("0.0.0.0", port, ["syslog"])
+ let(:nevents) { 100 }
+ let(:certificate) { RelpTest.certificate }
+ let(:port) { 5513 }
- event_count.times do
- client.syslog_write("Hello from client")
- client2.syslog_write("Hello from client 2")
+ let(:conf) do
+ <<-CONFIG
+ input {
+ relp {
+ type => "blah"
+ port => #{port}
+ ssl_enable => true
+ ssl_verify => false
+ ssl_cert => "#{certificate.ssl_cert}"
+ ssl_key => "#{certificate.ssl_key}"
+ }
+ }
+ CONFIG
+ end
+
+ let(:client) { RelpClient.new("0.0.0.0", port, ["syslog"], {:ssl => true}) }
+
+ let(:events) do
+ input(conf, nevents) do
+ nevents.times do
+ client.syslog_write("Hello from client")
+ end
end
+ end
- (event_count * 2).times.map{queue.pop}
+ context "registration and close" do
+
+ it "should register without errors" do
+ input = LogStash::Plugin.lookup("input", "relp").new("port" => 1235, "ssl_enable" => true,
+ "ssl_cert" => certificate.ssl_cert,
+ "ssl_key" => certificate.ssl_key)
+ expect {input.register}.to_not raise_error
+ end
+
end
- insist { events.select{|event| event["message"] == "Hello from client" }.size } == event_count
- insist { events.select{|event| event["message"] == "Hello from client 2" }.size } == event_count
+ it "should generated the events as expected" do
+ expect(events).to have(nevents).with("Hello from client")
+ end
+
end
+
end