Skip to content

Commit

Permalink
Merge pull request #4 from toshihirock/use_handle_tag_name
Browse files Browse the repository at this point in the history
apply Fluent::HandleTagName
  • Loading branch information
kentaro committed Nov 9, 2016
2 parents ea5e340 + c331c34 commit 4f7f958
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fluent/plugin/out_conditional_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def emit(tag, es, chain)
private

def filter_record(tag, time, record)
super
case filter
when 'numeric_upward'
filter_record = record.select do |key, value|
Expand Down
112 changes: 112 additions & 0 deletions spec/lib/out_conditional_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,118 @@
}
end
end

context('add_tag_prefix') do
let(:conf) {
%[
add_tag_prefix filtered.
key_pattern @example.com$
condition 10
filter numeric_upward
]
}

let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf) }
subject {
driver.instance
}

context('add tag prefix') do
before {
driver.run {
driver.emit('foo@example.com' => 12, 'bar@example.com' => 6, 'baz@baz.com' => 15)
}
}

it {
expect(driver.emits[0][0]).to be == 'filtered.test'
}
end
end

context('remove_tag_prefix') do
let(:conf) {
%[
remove_tag_prefix filtered.
key_pattern @example.com$
condition 10
filter numeric_upward
]
}

let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'filtered.filtered.test').configure(conf) }
subject {
driver.instance
}

context('remove tag prefix') do
before {
driver.run {
driver.emit('foo@example.com' => 12, 'bar@example.com' => 6, 'baz@baz.com' => 15)
}
}

it {
expect(driver.emits[0][0]).to be == 'filtered.test'
}
end
end

context('add_tag_suffix') do
let(:conf) {
%[
add_tag_suffix .test
key_pattern @example.com$
condition 10
filter numeric_upward
]
}

let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'filtered').configure(conf) }
subject {
driver.instance
}

context('add tag suffix') do
before {
driver.run {
driver.emit('foo@example.com' => 12, 'bar@example.com' => 6, 'baz@baz.com' => 15)
}
}

it {
expect(driver.emits[0][0]).to be == 'filtered.test'
}
end
end

context('remove_tag_suffix') do
let(:conf) {
%[
remove_tag_suffix .filtered
key_pattern @example.com$
condition 10
filter numeric_upward
]
}

let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'filtered.test.filtered').configure(conf) }
subject {
driver.instance
}

context('remove tag prefix') do
before {
driver.run {
driver.emit('foo@example.com' => 12, 'bar@example.com' => 6, 'baz@baz.com' => 15)
}
}

it {
expect(driver.emits[0][0]).to be == 'filtered.test'
}
end
end
end
end

0 comments on commit 4f7f958

Please sign in to comment.