fluent-plugin-serialport 0.14.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2eac908b71ab8f1d6478d7f6aae8f15c36751fe9
4
- data.tar.gz: 380a2b767e70166ebbf454755a3fc0bea30d32fc
2
+ SHA256:
3
+ metadata.gz: 79c6ad8fab882773e0043b7f87acf24422f3074b172bc65eb87b0c038d133394
4
+ data.tar.gz: 78d5b0e63d078151bec22d061c8b80bfd378fae304b37a8cad7cdef3c6c49772
5
5
  SHA512:
6
- metadata.gz: b6d0c68fcd4187054e7fb72f0584c73a695dd20de2784e63dc33d3d892a5519284de4e037081a17f35732a2b55a2c8b7a394f8898612ab9b31921f2f6e88031a
7
- data.tar.gz: fcbfb8d4bebaeb120d0ea69ce8085d33df50c9ff4dc385208b1459a0c078fe33850f2ed5e51ca0d2165ca4319d0aeece4a22faf0b9a1baaff06ad37deb8061bf
6
+ metadata.gz: b6db9dcf07c6264a36de437df35d241718fce3ae703c0251e965fa37dfba2bccedda478885e77c25b039640373ca99a2ac648d3de524650dc0cb6868e1a16663
7
+ data.tar.gz: 6f2c31fb35d41d16e093fffe43e2bdf6499c723028a01fd9a8114104d9688e42803b74fe513174116c2e6c080f0d2d52fe8176bc2457be8bf0ddfea95989829f
@@ -3,14 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-serialport"
6
- s.version = "0.14.1"
6
+ s.version = "1.0.0"
7
7
  s.authors = ["MATSUMOTO Katsuyoshi"]
8
8
  s.email = ["github@katsyoshi.org"]
9
9
  s.homepage = "https://github.com/katsyoshi/fluent-plugin-serialport"
10
10
  s.summary = "fluentd plugin for serial port"
11
11
  s.description = "fluentd plugin for serial port"
12
12
  s.license = "Apache License, Version 2.0"
13
- s.has_rdoc = false
14
13
 
15
14
  s.files = `git ls-files`.split("\n")
16
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -21,5 +20,7 @@ Gem::Specification.new do |s|
21
20
  s.add_dependency "serialport"
22
21
  s.add_development_dependency "simplecov"
23
22
  s.add_development_dependency "test-unit"
23
+ s.add_development_dependency "test-unit-rr"
24
+ s.add_development_dependency "timecop"
24
25
  s.add_development_dependency "rake"
25
26
  end
@@ -31,15 +31,14 @@ class SerialPortInput < Fluent::Plugin::Input
31
31
 
32
32
  def run
33
33
  loop do
34
- unless @serial.closed?
35
- begin
36
- timenow = @include_time ? Time.now.to_s << ' ' : ''
37
- data = {@device => timenow << @serial.readline(@eol)}
38
- router.emit(@tag, Engine.now, data)
39
- rescue
40
- $stderr.puts(caller) unless stopped?
41
- break
42
- end
34
+ break if @serial.closed?
35
+ begin
36
+ timenow = @include_time ? Time.now.to_s << ' ' : ''
37
+ data = {@device => timenow << @serial.readline(@eol)}
38
+ router.emit(@tag, Fluent::EventTime.now, data)
39
+ rescue => ex
40
+ log.warn(error: ex) unless stopped?
41
+ break
43
42
  end
44
43
  end
45
44
  end
@@ -3,10 +3,16 @@ require 'test_helper'
3
3
  class SerialPortInputTest < Test::Unit::TestCase
4
4
  def setup
5
5
  Fluent::Test.setup
6
+ @now = event_time("2018-06-04 11:57:00 +0900")
7
+ Timecop.freeze(Time.parse("2018-06-04 11:57:00 +0900"))
8
+ end
9
+
10
+ def teardown
11
+ Timecop.return
6
12
  end
7
13
 
8
14
  CONFIG = %[
9
- type serial_input
15
+ @type serial_input
10
16
  com_port serialport
11
17
  baud_rate 9600
12
18
  tag serialport
@@ -23,4 +29,76 @@ class SerialPortInputTest < Test::Unit::TestCase
23
29
  assert_equal 9600, d.instance.baud_rate
24
30
  assert_equal 'serialport', d.instance.tag
25
31
  end
32
+
33
+ sub_test_case("serial port") do
34
+ test "one line" do
35
+ mock(SerialPort).new("serialport", 9600, 8, 1, SerialPort::NONE) do
36
+ s = mock(Object.new)
37
+ n = 0
38
+ s.closed?.times(2) do
39
+ n += 1
40
+ n > 1
41
+ end
42
+ s.readline($/) { "This is a test\n" }
43
+ s.close
44
+ s
45
+ end
46
+ d = create_driver
47
+ d.run(expect_emits: 1)
48
+ events = d.events
49
+ assert_equal(1, events.size)
50
+ assert_equal(["serialport", @now, { "serialport" => "This is a test\n" }], events.first)
51
+ end
52
+
53
+ test "3 lines" do
54
+ mock(SerialPort).new("serialport", 9600, 8, 1, SerialPort::NONE) do
55
+ s = mock(Object.new)
56
+ n = 0
57
+ s.closed?.times(4) do
58
+ n += 1
59
+ n > 3
60
+ end
61
+ line = 0
62
+ s.readline($/).times(3) do
63
+ line += 1
64
+ "This is a test #{line}\n"
65
+ end
66
+ s.close
67
+ s
68
+ end
69
+ d = create_driver
70
+ d.run(expect_emits: 3)
71
+ events = d.events
72
+ assert_equal(3, events.size)
73
+ expected = [
74
+ ["serialport", @now, { "serialport" => "This is a test 1\n" }],
75
+ ["serialport", @now, { "serialport" => "This is a test 2\n" }],
76
+ ["serialport", @now, { "serialport" => "This is a test 3\n" }],
77
+ ]
78
+ assert_equal(expected, events)
79
+ end
80
+
81
+ test "raise and break" do
82
+ mock(SerialPort).new("serialport", 9600, 8, 1, SerialPort::NONE) do
83
+ s = mock(Object.new)
84
+ s.closed?.at_least(2) { false }
85
+ n = 0
86
+ s.readline($/).times(2) do
87
+ if n == 0
88
+ n += 1
89
+ "This is a test\n"
90
+ else
91
+ raise
92
+ end
93
+ end
94
+ s.close
95
+ s
96
+ end
97
+ d = create_driver
98
+ d.run(expect_emits: 1)
99
+ events = d.events
100
+ assert_equal(1, events.size)
101
+ assert_equal(["serialport", @now, { "serialport" => "This is a test\n" }], events.first)
102
+ end
103
+ end
26
104
  end
@@ -3,10 +3,15 @@ require 'simplecov'
3
3
  SimpleCov.start
4
4
 
5
5
  require 'test/unit'
6
+ require 'test/unit/rr'
7
+ require 'timecop'
6
8
 
7
9
  $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
8
10
  $LOAD_PATH.unshift(__dir__)
9
11
  require 'fluent/test'
12
+ require 'fluent/test/helpers'
10
13
  require 'fluent/test/driver/input'
11
14
 
12
15
  require 'fluent/plugin/in_serialport'
16
+
17
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-serialport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MATSUMOTO Katsuyoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2018-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -72,6 +72,34 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit-rr
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: timecop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
75
103
  - !ruby/object:Gem::Dependency
76
104
  name: rake
77
105
  requirement: !ruby/object:Gem::Requirement
@@ -123,10 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
151
  version: '0'
124
152
  requirements: []
125
153
  rubyforge_project:
126
- rubygems_version: 2.6.11
154
+ rubygems_version: 2.7.6
127
155
  signing_key:
128
156
  specification_version: 4
129
157
  summary: fluentd plugin for serial port
130
- test_files:
131
- - test/plugin/test_in_serialport.rb
132
- - test/test_helper.rb
158
+ test_files: []