Skip to content

Commit

Permalink
Add tests to cover codec autoswitch for stdin + tcp inputs
Browse files Browse the repository at this point in the history
json->json_lines & plain->line

Tests for elastic#1392
Closes elastic#1394
  • Loading branch information
jordansissel committed Jul 14, 2014
1 parent 0d3df38 commit bf518f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
23 changes: 23 additions & 0 deletions spec/inputs/stdin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# encoding: utf-8
require "test_utils"
require "socket"
require "logstash/inputs/stdin"

describe LogStash::Inputs::Stdin do
context "codec (PR #1372)" do
it "switches from plain to line" do
require "logstash/codecs/plain"
require "logstash/codecs/line"
plugin = LogStash::Inputs::Stdin.new("codec" => LogStash::Codecs::Plain.new)
plugin.register
insist { plugin.codec }.is_a?(LogStash::Codecs::Line)
end
it "switches from json to json_lines" do
require "logstash/codecs/json"
require "logstash/codecs/json_lines"
plugin = LogStash::Inputs::Stdin.new("codec" => LogStash::Codecs::JSON.new)
plugin.register
insist { plugin.codec }.is_a?(LogStash::Codecs::JSONLines)
end
end
end
35 changes: 25 additions & 10 deletions spec/inputs/tcp.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
# coding: utf-8
# encoding: utf-8
require "test_utils"
require "socket"
require "timeout"
require "logstash/json"
require "logstash/inputs/tcp"

describe "inputs/tcp" do
describe LogStash::Inputs::Tcp do
extend LogStash::RSpec

describe "read plain with unicode" do
context "codec (PR #1372)" do
it "switches from plain to line" do
require "logstash/codecs/plain"
require "logstash/codecs/line"
plugin = LogStash::Inputs::Tcp.new("codec" => LogStash::Codecs::Plain.new, "port" => 0)
plugin.register
insist { plugin.codec }.is_a?(LogStash::Codecs::Line)
end
it "switches from json to json_lines" do
require "logstash/codecs/json"
require "logstash/codecs/json_lines"
plugin = LogStash::Inputs::Tcp.new("codec" => LogStash::Codecs::JSON.new, "port" => 0)
plugin.register
insist { plugin.codec }.is_a?(LogStash::Codecs::JSONLines)
end
end

describe "read plain with unicode", :socket => true do
event_count = 10
port = 5511
config <<-CONFIG
Expand Down Expand Up @@ -39,7 +57,7 @@
end # input
end

describe "read events with plain codec and ISO-8859-1 charset" do
describe "read events with plain codec and ISO-8859-1 charset", :socket => true do
port = 5513
charset = "ISO-8859-1"
config <<-CONFIG
Expand Down Expand Up @@ -74,7 +92,7 @@
end # input
end

describe "read events with json codec" do
describe "read events with json codec", :socket => true do
port = 5514
config <<-CONFIG
input {
Expand Down Expand Up @@ -114,7 +132,7 @@
end # input
end

describe "read events with json codec (testing 'host' handling)" do
describe "read events with json codec (testing 'host' handling)", :socket => true do
port = 5514
config <<-CONFIG
input {
Expand Down Expand Up @@ -146,7 +164,7 @@
end # input
end

describe "read events with json_lines codec" do
describe "read events with json_lines codec", :socket => true do
port = 5515
config <<-CONFIG
input {
Expand Down Expand Up @@ -259,6 +277,3 @@
end # input
end
end



0 comments on commit bf518f7

Please sign in to comment.