fluent-plugin-dedot_filter 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md ADDED
@@ -0,0 +1,54 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ ## 1.1.0 - 2026-12-05
6
+
7
+ ### Fixed
8
+
9
+ - Records with Symbol or Integer keys are no longer routed to the error
10
+ stream. Symbol keys are de-dotted and stay Symbols; other non-string keys
11
+ are kept as they are (#12).
12
+ - With `de_dot_nested true`, keys of hashes inside arrays nested in arrays are
13
+ now rewritten (#12).
14
+
15
+ ### Changed
16
+
17
+ - Gem summary and description now describe the plugin and mention
18
+ OpenSearch (#12).
19
+ - Releases are published from GitHub Actions via RubyGems Trusted
20
+ Publishing (#10).
21
+
22
+ ## 1.0.1 - 2026-12-05
23
+
24
+ ### Fixed
25
+
26
+ - `de_dot false` no longer drops every record; records now pass through
27
+ unchanged (#6, #8).
28
+
29
+ ### Changed
30
+
31
+ - `required_ruby_version` is now `>= 2.7` (#7).
32
+ - CI moved from Travis CI to GitHub Actions and runs on Ruby 2.7 and
33
+ 3.1 - 4.0 (#7).
34
+ - Gem metadata now includes `source_code_uri`, `bug_tracker_uri` and
35
+ `rubygems_mfa_required` (#7).
36
+ - README expanded with a parameter table, examples, Docker / Helm notes and
37
+ development instructions (#7, #8).
38
+
39
+ ## 1.0.0 - 2017-12-03
40
+
41
+ ### Changed
42
+
43
+ - Migrated to the Fluentd v0.14 plugin API; requires Fluentd v0.14 or later
44
+ (#2).
45
+
46
+ ## 0.2.0 - 2016-05-30
47
+
48
+ ### Added
49
+
50
+ - `de_dot_nested` option to de-dot keys inside nested hashes and arrays (#1).
51
+
52
+ ## 0.1.0 - 2016-03-05
53
+
54
+ - Initial release.
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in fluent-plugin-dedot_filter.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'simplecov', require: false
8
+ end
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 TODO: Write your name
3
+ Copyright (c) 2017 Tomoyuki Sugimura
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,36 +1,65 @@
1
1
  # fluent-plugin-dedot_filter
2
2
 
3
- Fluentd Filter plugin to de-dot field name for elasticsearch.
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-dedot_filter.svg)](https://badge.fury.io/rb/fluent-plugin-dedot_filter)
4
+ [![Test](https://github.com/lunardial/fluent-plugin-dedot_filter/actions/workflows/test.yml/badge.svg)](https://github.com/lunardial/fluent-plugin-dedot_filter/actions/workflows/test.yml)
5
+ [![downloads](https://img.shields.io/gem/dt/fluent-plugin-dedot_filter.svg)](https://rubygems.org/gems/fluent-plugin-dedot_filter)
6
+ [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
7
+
8
+ A [Fluentd](https://www.fluentd.org/) filter plugin that replaces dots (`.`) in
9
+ record keys with another character (`_` by default).
10
+
11
+ Elasticsearch (2.x and later) and OpenSearch treat a dot in a field name as an
12
+ object path, so a key such as `kubernetes.labels.app.kubernetes.io/name` can
13
+ cause mapping conflicts or rejected documents. This filter rewrites such keys
14
+ before they reach the output plugin.
4
15
 
5
16
  ## Requirements
6
17
 
7
- | fluent-plugin-dedot_filter | fluentd |
8
- |-----------------------------|---------|
9
- | >= 1.0.0 | >= v0.14.0 |
10
- | < 1.0.0 | >= v0.12.0 |
18
+ | fluent-plugin-dedot_filter | fluentd | Ruby |
19
+ |----------------------------|------------|---------|
20
+ | >= 1.0.1 | >= v0.14.0 | >= 2.7 |
21
+ | 1.0.0 | >= v0.14.0 | - |
22
+ | < 1.0.0 | v0.12.x | - |
11
23
 
12
- ## Installation
24
+ The 1.x series is tested against Fluentd v1 on Ruby 2.7 and 3.1 - 4.0.
13
25
 
14
- Add this line to your application's Gemfile:
26
+ ## Installation
15
27
 
16
28
  ```bash
17
- # for fluentd v0.12
18
- gem install fluent-plugin-dedot_filter -v "< 1.0.0"
29
+ # for fluentd v1 / fluent-package (formerly td-agent)
30
+ fluent-gem install fluent-plugin-dedot_filter
31
+
32
+ # for fluentd v0.12 / td-agent2 (legacy)
33
+ fluent-gem install fluent-plugin-dedot_filter -v "< 1.0.0"
34
+ ```
35
+
36
+ Or add it to your Gemfile:
37
+
38
+ ```ruby
39
+ gem "fluent-plugin-dedot_filter"
40
+ ```
19
41
 
20
- # for fluentd v0.14 or higher
21
- gem install fluent-plugin-dedot_filter
42
+ ### Docker / Kubernetes (Helm)
22
43
 
23
- # for td-agent2
24
- td-agent-gem install fluent-plugin-dedot_filter -v "< 1.0.0"
44
+ Official Fluentd container images and Helm charts do not include this plugin.
45
+ If you see `Unknown filter plugin 'dedot'`, the gem is not installed in the
46
+ image. Build an image that installs it, for example:
25
47
 
26
- # for td-agent3
27
- td-agent-gem install fluent-plugin-dedot_filter
48
+ ```dockerfile
49
+ # use the Fluentd image tag you already run
50
+ FROM fluent/fluentd:v1.17-debian-1
51
+ USER root
52
+ RUN fluent-gem install fluent-plugin-dedot_filter
53
+ USER fluent
28
54
  ```
29
55
 
56
+ and point your chart at that image (or use the chart's plugin-install option,
57
+ if it has one).
58
+
30
59
  ## Usage
31
60
 
32
61
  ```xml
33
- <filter access.apache>
62
+ <filter kubernetes.**>
34
63
  @type dedot
35
64
  de_dot true
36
65
  de_dot_separator _
@@ -38,14 +67,72 @@ td-agent-gem install fluent-plugin-dedot_filter
38
67
  </filter>
39
68
  ```
40
69
 
41
- ## parameters
70
+ ## Parameters
71
+
72
+ | Name | Type | Default | Description |
73
+ |--------------------|--------|---------|-------------|
74
+ | `de_dot` | bool | `true` | Enables de-dotting. When `false`, records are passed through unchanged. |
75
+ | `de_dot_separator` | string | `_` | Replacement for each `.` in a key. Cannot be or contain `.`. |
76
+ | `de_dot_nested` | bool | `false` | Also rewrite keys inside nested hashes, including hashes inside (nested) arrays. |
77
+
78
+ Only keys are rewritten; values are never modified. String and Symbol keys are
79
+ de-dotted (Symbol keys stay Symbols); other keys, such as Integers, are kept as
80
+ they are.
81
+
82
+ > **Note:** versions up to 1.0.0 dropped every record when `de_dot false` was
83
+ > set ([#6](https://github.com/lunardial/fluent-plugin-dedot_filter/issues/6)).
84
+ > Upgrade if you rely on that setting.
85
+
86
+ ## Example
87
+
88
+ Input record:
89
+
90
+ ```json
91
+ {"app.name": "web", "kubernetes": {"labels": {"app.kubernetes.io/name": "web"}}, "msg": "a.b.c"}
92
+ ```
93
+
94
+ With the default settings (`de_dot_nested false`), only top-level keys change:
95
+
96
+ ```json
97
+ {"app_name": "web", "kubernetes": {"labels": {"app.kubernetes.io/name": "web"}}, "msg": "a.b.c"}
98
+ ```
99
+
100
+ With `de_dot_nested true`, nested keys change as well:
101
+
102
+ ```json
103
+ {"app_name": "web", "kubernetes": {"labels": {"app_kubernetes_io/name": "web"}}, "msg": "a.b.c"}
104
+ ```
105
+
106
+ If two keys collide after rewriting (for example `a.b` and `a_b`), the one
107
+ that appears later in the record wins.
108
+
109
+ ## Development
110
+
111
+ The easiest way to get a working environment is the included
112
+ [Dev Container](https://containers.dev/): open the repository in VS Code with
113
+ the Dev Containers extension (or in GitHub Codespaces) and choose
114
+ "Reopen in Container". Dependencies are installed automatically.
115
+
116
+ Then run:
117
+
118
+ ```bash
119
+ bundle exec rake spec
120
+
121
+ # with a local coverage report (coverage/index.html)
122
+ COVERAGE=1 bundle exec rake spec
123
+ ```
124
+
125
+ Without the Dev Container, any Docker host works:
126
+
127
+ ```bash
128
+ docker run --rm -v "$PWD":/app -w /app ruby:3.4 \
129
+ bash -c "bundle install && bundle exec rake spec"
130
+ ```
42
131
 
43
- * `de_dot` (default: true)
44
- * `de_dot_separator` (default: '_')
45
- * `de_dot_nested` (default: false)
132
+ Or, with Ruby installed locally, run `bundle install` first.
46
133
 
47
- `de_dot_separator` cannot be or contain '.'.
48
- `de_dot_nested` will cause the plugin to recurse through nested structures (hashes and arrays), and remove dots in those key-names too.
134
+ Bug reports and pull requests are welcome on
135
+ [GitHub](https://github.com/lunardial/fluent-plugin-dedot_filter).
49
136
 
50
137
  ## License
51
138
 
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
2
6
  task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
@@ -1,36 +1,34 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'fluent/plugin/filter_dedot/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "fluent-plugin-dedot_filter"
8
- spec.version = Fluent::Plugin::DedotFilter::VERSION
7
+ spec.version = File.read("VERSION").strip
9
8
  spec.authors = ["Tomoyuki Sugimura"]
10
- spec.email = ["tomoyuki.sugimura@gmail.com"]
9
+ spec.email = ["12116691+lunardial@users.noreply.github.com"]
11
10
 
12
- spec.summary = %q{de-dot field name for elasticsearch 2.x}
13
- spec.description = %q{de-dot field name for elasticsearch 2.x}
11
+ spec.summary = %q{Fluentd filter plugin that replaces dots in record keys}
12
+ spec.description = %q{A Fluentd filter plugin that replaces dots (.) in record keys with another character, so that Elasticsearch and OpenSearch do not treat them as object paths.}
14
13
  spec.homepage = "https://github.com/lunardial/fluent-plugin-dedot_filter"
15
14
  spec.license = "MIT"
15
+ spec.metadata = {
16
+ "source_code_uri" => "https://github.com/lunardial/fluent-plugin-dedot_filter",
17
+ "bug_tracker_uri" => "https://github.com/lunardial/fluent-plugin-dedot_filter/issues",
18
+ "rubygems_mfa_required" => "true",
19
+ }
16
20
 
17
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
- # delete this section to allow pushing this gem to any host.
19
- #if spec.respond_to?(:metadata)
20
- # spac.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- #else
22
- # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
- #end
24
-
25
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.files = `git ls-files`.split($/)
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
28
24
  spec.require_paths = ["lib"]
29
25
 
30
- spec.add_runtime_dependency "fluentd", [">= 0.14.0", "< 2"]
26
+ spec.required_ruby_version = ">= 2.7"
27
+
28
+ spec.add_runtime_dependency "fluentd", ">= 0.14.0", "< 2"
31
29
 
32
- spec.add_development_dependency "bundler", "~> 1.11"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec"
35
- spec.add_development_dependency "test-unit"
30
+ spec.add_development_dependency "bundler"
31
+ spec.add_development_dependency "rake", ">= 13.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "test-unit", "~> 3.0"
36
34
  end
@@ -27,10 +27,15 @@ module Fluent::Plugin
27
27
  end
28
28
 
29
29
  def filter(tag, time, record)
30
+ # Returning nil from a filter drops the record, so pass it through
31
+ # untouched when de-dotting is disabled.
32
+ return record unless @de_dot
33
+
30
34
  begin
31
- de_dot(record) if @de_dot
35
+ de_dot(record)
32
36
  rescue => e
33
37
  router.emit_error_event(tag, time, record, e)
38
+ nil
34
39
  end
35
40
  end
36
41
 
@@ -38,22 +43,38 @@ module Fluent::Plugin
38
43
  newrecord = {}
39
44
 
40
45
  record.each do |key, value|
41
- newkey = key.gsub(/\./, @de_dot_separator)
42
-
43
- # Recurse hashes and arrays:
44
- if @de_dot_nested
45
- if value.is_a? Hash
46
- value = de_dot value
47
- elsif value.is_a? Array
48
- value = value.map { |v| v.is_a?(Hash) ? de_dot(v) : v }
49
- end
50
- end
51
-
52
- newrecord[newkey] = value
46
+ newrecord[de_dot_key(key)] = @de_dot_nested ? de_dot_value(value) : value
53
47
  end
54
48
 
55
49
  newrecord
56
50
  end
57
51
 
52
+ private
53
+
54
+ # Only String and Symbol keys can contain dots; other keys (for example
55
+ # Integer keys produced by some parsers) are kept as they are.
56
+ def de_dot_key(key)
57
+ case key
58
+ when String
59
+ key.gsub(/\./, @de_dot_separator)
60
+ when Symbol
61
+ key.to_s.gsub(/\./, @de_dot_separator).to_sym
62
+ else
63
+ key
64
+ end
65
+ end
66
+
67
+ # Recurse into hashes and arrays, including arrays nested in arrays.
68
+ def de_dot_value(value)
69
+ case value
70
+ when Hash
71
+ de_dot(value)
72
+ when Array
73
+ value.map { |v| de_dot_value(v) }
74
+ else
75
+ value
76
+ end
77
+ end
78
+
58
79
  end
59
80
  end
@@ -0,0 +1,260 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'helper'
4
+
5
+ class TestDedotFilter
6
+ RSpec.describe Fluent::Plugin::DedotFilter do
7
+
8
+ CONFIG = %[]
9
+
10
+ def create_driver(conf=CONFIG)
11
+ Fluent::Test::Driver::Filter.new(Fluent::Plugin::DedotFilter).configure(conf)
12
+ end
13
+
14
+ def filter_records(conf, records)
15
+ driver = create_driver(conf)
16
+ driver.run(default_tag: 'test') do
17
+ records.each { |record| driver.feed(record) }
18
+ end
19
+ driver.filtered_records
20
+ end
21
+
22
+ def create_filter
23
+ Fluent::Plugin::DedotFilter.new
24
+ end
25
+
26
+ before :all do
27
+ Fluent::Test.setup
28
+ end
29
+
30
+ before :each do
31
+ @filter = create_filter
32
+ end
33
+
34
+ context "#filter" do
35
+
36
+ it "de-dots keys when de_dot is true (default)" do
37
+ records = filter_records(%[], [{"key.dot" => "value"}])
38
+ expect(records).to eq [{"key_dot" => "value"}]
39
+ end
40
+
41
+ it "uses de_dot_separator" do
42
+ records = filter_records(%[de_dot_separator -], [{"key.dot" => "value"}])
43
+ expect(records).to eq [{"key-dot" => "value"}]
44
+ end
45
+
46
+ it "passes records through untouched when de_dot is false" do
47
+ input = [{"key.dot" => "value"}, {"a.b" => {"c.d" => 1}}]
48
+ records = filter_records(%[de_dot false], input)
49
+ expect(records).to eq input
50
+ end
51
+
52
+ it "allows a separator containing '.' when de_dot is false" do
53
+ expect { create_driver(%[de_dot false\nde_dot_separator .]) }.not_to raise_error
54
+ end
55
+
56
+ it "rejects a separator containing '.' when de_dot is true" do
57
+ expect { create_driver(%[de_dot_separator .]) }.to raise_error(Fluent::ConfigError)
58
+ end
59
+
60
+ it "uses the documented defaults" do
61
+ filter = create_driver.instance
62
+ # The plugin's de_dot(record) method shadows the de_dot config
63
+ # reader, so read the configured value directly.
64
+ expect(filter.instance_variable_get(:@de_dot)).to eq true
65
+ expect(filter.de_dot_separator).to eq "_"
66
+ expect(filter.de_dot_nested).to eq false
67
+ end
68
+
69
+ it "supports a multi-character separator" do
70
+ records = filter_records(%[de_dot_separator __], [{"a.b.c" => 1}])
71
+ expect(records).to eq [{"a__b__c" => 1}]
72
+ end
73
+
74
+ it "leaves values containing dots untouched" do
75
+ records = filter_records(%[], [{"host.name" => "web.example.com"}])
76
+ expect(records).to eq [{"host_name" => "web.example.com"}]
77
+ end
78
+
79
+ it "only rewrites top-level keys when de_dot_nested is false" do
80
+ input = {"a.b" => {"c.d" => 1}, "e.f" => [{"g.h" => 2}]}
81
+ records = filter_records(%[], [input])
82
+ expect(records).to eq [{"a_b" => {"c.d" => 1}, "e_f" => [{"g.h" => 2}]}]
83
+ end
84
+
85
+ it "rewrites nested hash and array keys when de_dot_nested is true" do
86
+ input = {"a.b" => {"c.d" => {"e.f" => 1}}, "g.h" => [{"i.j" => 2}, "k.l", 3]}
87
+ records = filter_records(%[de_dot_nested true], [input])
88
+ expect(records).to eq [{"a_b" => {"c_d" => {"e_f" => 1}}, "g_h" => [{"i_j" => 2}, "k.l", 3]}]
89
+ end
90
+
91
+ it "processes every record in a stream" do
92
+ input = [{"a.b" => 1}, {"c.d" => 2}, {"no_dot" => 3}]
93
+ records = filter_records(%[], input)
94
+ expect(records).to eq [{"a_b" => 1}, {"c_d" => 2}, {"no_dot" => 3}]
95
+ end
96
+
97
+ it "does not mutate the incoming record" do
98
+ input = {"a.b" => {"c.d" => 1}}
99
+ filter_records(%[de_dot_nested true], [input])
100
+ expect(input).to eq({"a.b" => {"c.d" => 1}})
101
+ end
102
+
103
+ it "routes records that fail to process to the error stream" do
104
+ driver = create_driver
105
+ allow(driver.instance).to receive(:de_dot).and_wrap_original do |original, record|
106
+ raise "boom" if record.key?("boom")
107
+ original.call(record)
108
+ end
109
+ driver.run(default_tag: 'test') do
110
+ driver.feed({"boom" => "value"})
111
+ driver.feed({"a.b" => "ok"})
112
+ end
113
+ expect(driver.filtered_records).to eq [{"a_b" => "ok"}]
114
+ expect(driver.error_events.size).to eq 1
115
+ end
116
+
117
+ it "de-dots symbol keys and keeps them as symbols" do
118
+ records = filter_records(%[], [{:"a.b" => 1, :c => 2}])
119
+ expect(records).to eq [{:a_b => 1, :c => 2}]
120
+ end
121
+
122
+ it "keeps non-string keys instead of dropping the record" do
123
+ driver = create_driver
124
+ driver.run(default_tag: 'test') do
125
+ driver.feed({1 => "int", nil => "nil", "a.b" => 2})
126
+ end
127
+ expect(driver.filtered_records).to eq [{1 => "int", nil => "nil", "a_b" => 2}]
128
+ expect(driver.error_events).to be_empty
129
+ end
130
+
131
+ it "de-dots non-string keys inside nested hashes when de_dot_nested is true" do
132
+ input = {"a.b" => {1 => "int", :"c.d" => 2}}
133
+ records = filter_records(%[de_dot_nested true], [input])
134
+ expect(records).to eq [{"a_b" => {1 => "int", :c_d => 2}}]
135
+ end
136
+
137
+ it "rewrites hashes in arrays nested in arrays when de_dot_nested is true" do
138
+ input = {"a.b" => [[{"c.d" => 1}, ["e.f", [{"g.h" => 2}]]], {"i.j" => [[]]}]}
139
+ records = filter_records(%[de_dot_nested true], [input])
140
+ expect(records).to eq [{"a_b" => [[{"c_d" => 1}, ["e.f", [{"g_h" => 2}]]], {"i_j" => [[]]}]}]
141
+ end
142
+
143
+ it "leaves arrays nested in arrays untouched when de_dot_nested is false" do
144
+ input = {"a.b" => [[{"c.d" => 1}]]}
145
+ records = filter_records(%[], [input])
146
+ expect(records).to eq [{"a_b" => [[{"c.d" => 1}]]}]
147
+ end
148
+
149
+ end
150
+
151
+ context "#de_dot" do
152
+
153
+ it "no error because of empty record" do
154
+ expect(@filter.de_dot({})).to eq Hash.new
155
+ end
156
+
157
+ it "no error with non recursive hash" do
158
+ @filter.de_dot_nested = false
159
+ test_hash = {}
160
+ test_hash["key"] = "value"
161
+ test_hash["key.dot"] = "value.dot"
162
+ expect_hash = {}
163
+ expect_hash["key"] = test_hash["key"]
164
+ expect_hash["key_dot"] = test_hash["key.dot"]
165
+ expect(@filter.de_dot(test_hash)).to eq expect_hash
166
+ end
167
+
168
+ it "no error with recursive hash with de_dot_nested = false" do
169
+ # "child_dot" => {"key"=>"value", "key.dot"=>"value.dot"}
170
+ @filter.de_dot_nested = false
171
+ test_child_hash = {}
172
+ test_child_hash["key"] = "value"
173
+ test_child_hash["key.dot"] = "value.dot"
174
+ test_hash = {}
175
+ test_hash["key"] = "value"
176
+ test_hash["child.dot"] = test_child_hash
177
+ expect_child_hash = {}
178
+ expect_child_hash["key"] = test_child_hash["key"]
179
+ expect_child_hash["key.dot"] = test_child_hash["key.dot"]
180
+ expect_hash = {}
181
+ expect_hash["key"] = "value"
182
+ expect_hash["child_dot"] = expect_child_hash
183
+ expect(@filter.de_dot(test_hash)).to eq expect_hash
184
+ end
185
+
186
+ it "no error with recursive hash with de_dot_nested = true" do
187
+ # "child_dot" => {"key"=>"value", "key_dot"=>"value.dot"}
188
+ @filter.de_dot_nested = true
189
+ test_child_hash = {}
190
+ test_child_hash["key"] = "value"
191
+ test_child_hash["key.dot"] = "value.dot"
192
+ test_hash = {}
193
+ test_hash["key"] = "value"
194
+ test_hash["child.dot"] = test_child_hash
195
+ expect_child_hash = {}
196
+ expect_child_hash["key"] = test_child_hash["key"]
197
+ expect_child_hash["key_dot"] = test_child_hash["key.dot"]
198
+ expect_hash = {}
199
+ expect_hash["key"] = "value"
200
+ expect_hash["child_dot"] = expect_child_hash
201
+ expect(@filter.de_dot(test_hash)).to eq expect_hash
202
+ end
203
+
204
+ it "no error with recursive array with de_dot_nested = false" do
205
+ # "child_dot" => ["test", "test.dot", {"key"=>"value", "key.dot"=>"value.dot"}]
206
+ @filter.de_dot_nested = false
207
+ test_child_hash = {}
208
+ test_child_hash["key"] = "value"
209
+ test_child_hash["key.dot"] = "value.dot"
210
+ test_child_array = []
211
+ test_child_array.push("test")
212
+ test_child_array.push("test.dot")
213
+ test_child_array.push(test_child_hash)
214
+ test_hash = {}
215
+ test_hash["key"] = "value"
216
+ test_hash["child.dot"] = test_child_array
217
+ expect_child_hash = {}
218
+ expect_child_hash["key"] = test_child_hash["key"]
219
+ expect_child_hash["key.dot"] = test_child_hash["key.dot"]
220
+ expect_child_array = []
221
+ expect_child_array.push("test")
222
+ expect_child_array.push("test.dot")
223
+ expect_child_array.push(expect_child_hash)
224
+ expect_hash = {}
225
+ expect_hash["key"] = "value"
226
+ expect_hash["child_dot"] = expect_child_array
227
+ expect(@filter.de_dot(test_hash)).to eq expect_hash
228
+ end
229
+
230
+ it "no error with recursive array with de_dot_nested = true" do
231
+ # "child_dot" => ["test", "test.dot", {"key"=>"value", "key_dot"=>"value.dot"}]
232
+ @filter.de_dot_nested = true
233
+ test_child_hash = {}
234
+ test_child_hash["key"] = "value"
235
+ test_child_hash["key.dot"] = "value.dot"
236
+ test_child_array = []
237
+ test_child_array.push("test")
238
+ test_child_array.push("test.dot")
239
+ test_child_array.push(test_child_hash)
240
+ test_hash = {}
241
+ test_hash["key"] = "value"
242
+ test_hash["child.dot"] = test_child_array
243
+ expect_child_hash = {}
244
+ expect_child_hash["key"] = test_child_hash["key"]
245
+ expect_child_hash["key_dot"] = test_child_hash["key.dot"]
246
+ expect_child_array = []
247
+ expect_child_array.push("test")
248
+ expect_child_array.push("test.dot")
249
+ expect_child_array.push(expect_child_hash)
250
+ expect_hash = {}
251
+ expect_hash["key"] = "value"
252
+ expect_hash["child_dot"] = expect_child_array
253
+ expect(@filter.de_dot(test_hash)).to eq expect_hash
254
+ end
255
+
256
+ end
257
+
258
+ end
259
+
260
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems."
11
+ exit e.status_code
12
+ end
13
+
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+
17
+ unless ENV.has_key?('VERBOSE')
18
+ nulllogger = Object.new
19
+ nulllogger.instance_eval { |obj|
20
+ def method_missing(method, *args)
21
+ #pass
22
+ end
23
+ }
24
+ $log = nulllogger
25
+ end
26
+
27
+ require 'fluent/test'
28
+ # fluent/test loads test-unit, whose at_exit autorunner would otherwise try
29
+ # to parse RSpec's command-line options (e.g. --pattern) and fail the run.
30
+ Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner)
31
+ require 'fluent/test/driver/filter'
32
+ require 'fluent/plugin/filter_dedot'