Skip to content

Commit

Permalink
Expose record_accessor internal instance @keys variable. Fix #1806
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo0920 committed Dec 29, 2017
1 parent 68798f5 commit 8e7358f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/fluent/plugin_helper/record_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def record_accessor_create(param)
end

class Accessor
attr_reader :keys

def initialize(param)
@keys = Accessor.parse_parameter(param)

Expand Down
34 changes: 34 additions & 0 deletions test/plugin_helper/test_record_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,40 @@ class Dummy < Fluent::Plugin::TestBase
end
end

sub_test_case 'attr_reader :keys' do
setup do
@d = Dummy.new
end

data('normal' => 'key1',
'space' => 'ke y2',
'dot key' => 'this.is.key3')
test 'access single key' do |param|
accessor = @d.record_accessor_create(param)
assert_equal param, accessor.keys
end

test "nested bracket keys with dot" do
accessor = @d.record_accessor_create("$['key1']['this.is.key3']")
assert_equal ['key1','this.is.key3'], accessor.keys
end

data('dot' => '$.key1.key2[0]',
'bracket' => "$['key1']['key2'][0]",
'bracket w/ double quotes' => '$["key1"]["key2"][0]')
test "nested keys ['key1', 'key2', 0]" do |param|
accessor = @d.record_accessor_create(param)
assert_equal ['key1', 'key2', 0], accessor.keys
end

data('bracket' => "$['key1'][0]['ke y2']",
'bracket w/ double quotes' => '$["key1"][0]["ke y2"]')
test "nested keys ['key1', 0, 'ke y2']" do |param|
accessor = @d.record_accessor_create(param)
assert_equal ['key1', 0, 'ke y2'], accessor.keys
end
end

sub_test_case Fluent::PluginHelper::RecordAccessor::Accessor do
setup do
@d = Dummy.new
Expand Down

0 comments on commit 8e7358f

Please sign in to comment.