@@ -16,73 +16,81 @@ def setup
1616 tag_field_name tag
1717 ]
1818
19- def create_driver ( conf = CONFIG , tag = 'azure-loganalytics.test' )
20- Fluent ::Test ::BufferedOutputTestDriver . new ( Fluent ::AzureLogAnalyticsOutput , tag ) . configure ( conf )
19+ def create_driver ( conf = CONFIG )
20+ Fluent ::Test ::Driver :: Output . new ( Fluent ::Plugin :: AzureLogAnalyticsOutput ) . configure ( conf )
2121 end
2222
2323 def test_configure
24- #### set configurations
25- # d = create_driver %[
26- # path test_path
27- # compress gz
28- # ]
29- #### check configurations
30- # assert_equal 'test_path', d.instance.path
31- # assert_equal :gz , d.instance.compress
24+ d = create_driver
25+ assert_equal '<Customer ID aka WorkspaceID String>' , d . instance . customer_id
26+ assert_equal '<Primary Key String>' , d . instance . shared_key
27+ assert_equal 'ApacheAccessLog' , d . instance . log_type
28+ assert_true d . instance . add_time_field
29+ assert_true d . instance . localtime
30+ assert_true d . instance . add_tag_field
31+ assert_equal 'tag' , d . instance . tag_field_name
3232 end
3333
3434 def test_format
35- # d = create_driver
36- # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
37- # d.emit({"a"=>1}, time)
38- # d.emit({"a"=>2}, time)
39-
40- # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
41- # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
42-
43- # d.run
35+ d = create_driver
36+ time = event_time ( "2011-01-02 13:14:15 UTC" )
37+ d . run ( default_tag : 'test' ) do
38+ d . feed ( time , { "a" => 1 } )
39+ d . feed ( time , { "a" => 2 } )
40+ end
41+ formatted = d . formatted
42+ unpacker = Fluent ::Engine . msgpack_factory . unpacker
43+ formatted . each_with_index { |f , idx |
44+ unpacker . feed_each ( f ) . each { |e |
45+ assert_equal idx +1 , e [ "a" ]
46+ assert_equal "test" , e [ "tag" ]
47+ assert_equal "#{ time . to_i } " , e [ "time" ]
48+ }
49+ }
4450 end
4551
4652 def test_write
4753 d = create_driver
4854
49- time = Time . parse ( "2016-12-10 13:14:15 UTC" ) . to_i
50- d . emit (
51- {
52- :Log_ID => "5cdad72f-c848-4df0-8aaa-ffe033e75d57" ,
53- :date => "2016-12-10 09:44:32 JST" ,
54- :processing_time => "372" ,
55- :remote => "101.202.74.59" ,
56- :user => "-" ,
57- :method => "GET / HTTP/1.1" ,
58- :status => "304" ,
59- :size => "-" ,
60- :referer => "-" ,
61- :agent => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:27.0) Gecko/20100101 Firefox/27.0" ,
62- :eventtime => "2016-12-10T09:44:32Z"
63- } , time )
64-
65- d . emit (
66- {
67- :Log_ID => "7260iswx-8034-4cc3-uirtx-f068dd4cd659" ,
68- :date => "2016-12-10 09:45:14 JST" ,
69- :processing_time => "105" ,
70- :remote => "201.78.74.59" ,
71- :user => "-" ,
72- :method => "GET /manager/html HTTP/1.1" ,
73- :status => "200" ,
74- :size => "-" ,
75- :referer => "-" ,
76- :agent => "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0" ,
77- :eventtime => "2016-12-10T09:45:14Z"
78- } , time )
55+ time = event_time ( "2016-12-10 13:14:15 UTC" )
56+ d . run ( default_tag : 'azure-loganalytics.test' ) do
57+ d . feed (
58+ time ,
59+ {
60+ :Log_ID => "5cdad72f-c848-4df0-8aaa-ffe033e75d57" ,
61+ :date => "2016-12-10 09:44:32 JST" ,
62+ :processing_time => "372" ,
63+ :remote => "101.202.74.59" ,
64+ :user => "-" ,
65+ :method => "GET / HTTP/1.1" ,
66+ :status => "304" ,
67+ :size => "-" ,
68+ :referer => "-" ,
69+ :agent => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:27.0) Gecko/20100101 Firefox/27.0" ,
70+ :eventtime => "2016-12-10T09:44:32Z"
71+ } )
7972
80- data = d . run
73+ d . feed (
74+ time ,
75+ {
76+ :Log_ID => "7260iswx-8034-4cc3-uirtx-f068dd4cd659" ,
77+ :date => "2016-12-10 09:45:14 JST" ,
78+ :processing_time => "105" ,
79+ :remote => "201.78.74.59" ,
80+ :user => "-" ,
81+ :method => "GET /manager/html HTTP/1.1" ,
82+ :status => "200" ,
83+ :size => "-" ,
84+ :referer => "-" ,
85+ :agent => "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0" ,
86+ :eventtime => "2016-12-10T09:45:14Z"
87+ } )
88+ end
89+ data = d . events
8190 puts data
8291 # ### FileOutput#write returns path
8392 # path = d.run
8493 # expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
8594 # assert_equal expect_path, path
8695 end
8796end
88-
0 commit comments