Skip to content

Commit bf0acd8

Browse files
committed
add config test
1 parent 1761062 commit bf0acd8

File tree

6 files changed

+101
-1
lines changed

6 files changed

+101
-1
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Release 0.1.1 - 2015/02/02
2+
3+
* add config test
4+
15
Release 0.1.0 - 2014/10/22
26

37
* First commit
8+

Rakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
require "bundler/gem_tasks"
2+
require 'rake/testtask'
3+
4+
Rake::TestTask.new(:test) do |test|
5+
test.libs << 'lib' << 'test'
6+
test.test_files = FileList['test/test_*.rb']
7+
test.verbose = true
8+
end
9+
10+
task :default => [:build]
211

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.1.1

fluent-plugin-dynamodb-add.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
1919

2020
spec.add_development_dependency "bundler", "~> 1.7"
2121
spec.add_development_dependency "rake", "~> 10.0"
22+
#spec.add_development_dependency "fake_dynamo", "~> 0.2.5"
2223
spec.add_dependency "fluentd", "~> 0.10.0"
2324
spec.add_dependency "aws-sdk", ">= 1.56.0"
2425
end

lib/fluent/plugin/out_dynamodb_add.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def start
5252
end
5353

5454
def emit(tag, es, chain)
55+
chain.next
5556
es.each do |time, record|
5657
hash_key = create_key(record)
5758
next unless hash_key || record[@count_key]

test/test_out_dynamodb_add.rb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
require 'fluent/test'
2+
require 'fluent/plugin/out_dynamodb_add'
3+
4+
class DynamodbAddTest < Test::Unit::TestCase
5+
def setup
6+
Fluent::Test.setup
7+
end
8+
9+
CONFIG = %[
10+
count_key test_count_key
11+
dynamo_count_key test_dynamo_count_key
12+
table_name test_table_name
13+
use_iam_role false
14+
aws_key_id test_aws_key_id
15+
aws_sec_key test_aws_sec_key
16+
endpoint https://test_endpoint
17+
hash_key test_hash_key1,test_hash_key2
18+
hash_key_delimiter :
19+
add_hash_key_prefix 3
20+
range_key test_range_key
21+
]
22+
23+
def create_driver(conf = CONFIG)
24+
Fluent::Test::OutputTestDriver.new(Fluent::DynamodbAdd) do
25+
def write(chunk)
26+
chunk.read
27+
end
28+
end.configure(conf)
29+
end
30+
31+
def test_configure_not_use_iam_role
32+
d = create_driver
33+
assert_equal 'test_count_key', d.instance.count_key
34+
assert_equal 'test_dynamo_count_key', d.instance.dynamo_count_key
35+
assert_equal 'test_table_name', d.instance.table_name
36+
assert_equal false, d.instance.use_iam_role
37+
assert_equal 'test_aws_key_id', d.instance.aws_key_id
38+
assert_equal 'test_aws_sec_key', d.instance.aws_sec_key
39+
assert_equal 'https://test_endpoint', d.instance.endpoint
40+
assert_equal ['test_hash_key1','test_hash_key2'], d.instance.hash_key
41+
assert_equal ':', d.instance.hash_key_delimiter
42+
assert_equal '3', d.instance.add_hash_key_prefix
43+
assert_equal 'test_range_key', d.instance.range_key
44+
end
45+
46+
def test_configure_use_iam_role
47+
conf = CONFIG.clone
48+
conf.gsub!(/use_iam_role\sfalse/, "use_iam_role true")
49+
conf.gsub!(/aws_key_id\stest_aws_key_id/, "")
50+
conf.gsub!(/aws_sec_key\stest_aws_sec_key/, "")
51+
52+
d = create_driver(conf)
53+
assert_equal 'test_count_key', d.instance.count_key
54+
assert_equal 'test_dynamo_count_key', d.instance.dynamo_count_key
55+
assert_equal 'test_table_name', d.instance.table_name
56+
assert_equal true, d.instance.use_iam_role
57+
assert_equal nil, d.instance.aws_key_id
58+
assert_equal nil, d.instance.aws_sec_key
59+
assert_equal 'https://test_endpoint', d.instance.endpoint
60+
assert_equal ['test_hash_key1','test_hash_key2'], d.instance.hash_key
61+
assert_equal ':', d.instance.hash_key_delimiter
62+
assert_equal '3', d.instance.add_hash_key_prefix
63+
assert_equal 'test_range_key', d.instance.range_key
64+
end
65+
66+
def test_configure_not_use_iam_role_and_not_set_range_key
67+
conf = CONFIG.clone
68+
conf.gsub!(/range_key\stest_range_key/, "")
69+
70+
d = create_driver(conf)
71+
assert_equal 'test_count_key', d.instance.count_key
72+
assert_equal 'test_dynamo_count_key', d.instance.dynamo_count_key
73+
assert_equal 'test_table_name', d.instance.table_name
74+
assert_equal false, d.instance.use_iam_role
75+
assert_equal 'test_aws_key_id', d.instance.aws_key_id
76+
assert_equal 'test_aws_sec_key', d.instance.aws_sec_key
77+
assert_equal 'https://test_endpoint', d.instance.endpoint
78+
assert_equal ['test_hash_key1','test_hash_key2'], d.instance.hash_key
79+
assert_equal ':', d.instance.hash_key_delimiter
80+
assert_equal '3', d.instance.add_hash_key_prefix
81+
assert_equal nil, d.instance.range_key
82+
end
83+
end
84+

0 commit comments

Comments
 (0)