-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collectd::plugin::modbus: reformat data type aliases and add spec tests
- Loading branch information
Showing
6 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Collectd::Modbus::Data' do | ||
it do | ||
is_expected.to allow_values({ | ||
'type' => 'foo', | ||
'register_base' => 123, | ||
'register_type' => 'Int32', | ||
}) | ||
end | ||
|
||
it do | ||
is_expected.to allow_values({ | ||
'type' => 'foo', | ||
'register_base' => 123, | ||
'register_type' => 'Int32', | ||
'register_cmd' => 'ReadInput', | ||
}) | ||
end | ||
|
||
it do | ||
is_expected.to allow_values({ | ||
'instance' => 'foobar', | ||
'type' => 'foo', | ||
'register_base' => 123, | ||
'register_type' => 'Int32', | ||
}) | ||
end | ||
|
||
it { is_expected.not_to allow_values(nil) } | ||
it { is_expected.not_to allow_values({ 'type' => 'foo', 'register_base' => 123 }) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Collectd::Modbus::Host' do | ||
let(:slaves) do | ||
{ | ||
1 => { 'instance' => 'foo1', 'collect' => 'bar1' }, | ||
2 => { 'instance' => 'foo2', 'collect' => %w[bar1 bar2] }, | ||
} | ||
end | ||
|
||
it { is_expected.to allow_values({ 'address' => '127.0.0.1', 'port' => 1234, 'slaves' => slaves }) } | ||
it { is_expected.to allow_values({ 'address' => '127.0.0.1', 'port' => 1234, 'slaves' => slaves, 'interval' => 120 }) } | ||
|
||
it { is_expected.not_to allow_values(nil) } | ||
it { is_expected.not_to allow_values({ 'address' => '127.0.0.1', 'port' => '1234', 'slaves' => slaves, 'interval' => 120 }) } | ||
it { is_expected.not_to allow_values({ 'port' => 1234, 'slaves' => slaves, 'interval' => 120 }) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Collectd::Modbus::Slave' do | ||
it { is_expected.to allow_values({ 'instance' => 'foo1', 'collect' => 'bar1' }) } | ||
it { is_expected.to allow_values({ 'instance' => 'foo1', 'collect' => %w[bar1 bar2] }) } | ||
|
||
it { is_expected.not_to allow_values(nil) } | ||
it { is_expected.not_to allow_values({ 'collect' => ['bar1'] }) } | ||
it { is_expected.not_to allow_values({ 'instance' => 'foo1' }) } | ||
it { is_expected.not_to allow_values({ 'instance' => 'foo1', 'collect' => [] }) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# | ||
# @summary represents a modbus data entry | ||
type Collectd::Modbus::Data = Struct[{ | ||
Optional['instance'] => String, | ||
NotUndef['type'] => String[1], | ||
NotUndef['register_base'] => Integer[0], | ||
NotUndef['register_type'] => Enum['Int16', 'Int32', 'Uint16', 'Uint32', 'Float'], | ||
Optional['register_cmd'] => Enum['ReadHolding', 'ReadInput'], | ||
Optional['instance'] => String, | ||
NotUndef['type'] => String[1], | ||
NotUndef['register_base'] => Integer[0], | ||
NotUndef['register_type'] => Enum['Int16', 'Int32', 'Uint16', 'Uint32', 'Float'], | ||
Optional['register_cmd'] => Enum['ReadHolding', 'ReadInput'], | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# | ||
type Collectd::Modbus::Host = Struct[{NotUndef['address'] => String[1], NotUndef['port'] => String[1], NotUndef['slaves'] => Hash[Integer, Collectd::Modbus::Slave], Optional['interval'] => Integer[0]}] | ||
# @summary represents a modbus host entry | ||
type Collectd::Modbus::Host = Struct[{ | ||
NotUndef['address'] => String[1], | ||
NotUndef['port'] => Stdlib::Port, | ||
NotUndef['slaves'] => Hash[Integer, Collectd::Modbus::Slave], | ||
Optional['interval'] => Integer[0] | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# | ||
type Collectd::Modbus::Slave = Struct[{NotUndef['instance'] => String[1], NotUndef['collect'] => Variant[String[1], Array[String[1], 1]]}] | ||
# @summary Represents a modbus host's slave entry | ||
type Collectd::Modbus::Slave = Struct[{ | ||
NotUndef['instance'] => String[1], | ||
NotUndef['collect'] => Variant[ | ||
String[1], | ||
Array[String[1], 1] | ||
] | ||
}] |