@@ -9,7 +9,78 @@ class Fluent::TailCheckerTest < Test::Unit::TestCase
99 end
1010 end
1111
12- test "something useful" do
13- assert_equal ( "actual" , "actual" )
12+ sub_test_case "Parse args" do
13+ data (
14+ "Minimum" ,
15+ [
16+ [ "/path/to/pos" ] ,
17+ { pos_filepaths : [ "/path/to/pos" ] , follow_inodes : false } ,
18+ ]
19+ )
20+ data (
21+ "Full" ,
22+ [
23+ [ "--follow_inodes" , "/path/to/pos" , "/path/to/pos2" ] ,
24+ { pos_filepaths : [ "/path/to/pos" , "/path/to/pos2" ] , follow_inodes : true } ,
25+ ]
26+ )
27+ test "Correct args" do |( args , expected ) |
28+ tail_check = Fluent ::TailChecker ::TailCheck . new
29+
30+ tail_check . parse_command_line ( args )
31+
32+ result = {
33+ pos_filepaths : tail_check . instance_variable_get ( :@pos_filepaths ) ,
34+ follow_inodes : tail_check . instance_variable_get ( :@follow_inodes ) ,
35+ }
36+ assert_equal ( expected , result )
37+ end
38+
39+ data ( "Invalid options" , [ "--foo" , "/path/to/pos" ] )
40+ test "Raise error for invalid options" do |args |
41+ tail_check = Fluent ::TailChecker ::TailCheck . new
42+
43+ assert_raise ( OptionParser ::InvalidOption ) do
44+ tail_check . parse_command_line ( args )
45+ end
46+ end
47+ end
48+
49+ sub_test_case "Validate pos_file paths" do
50+ data (
51+ "Mixed existant and nonexistant paths" ,
52+ [
53+ [ "test/data/pos_normal" , "foo" , "test/data/pos_follow_inodes_normal" , "bar" ] ,
54+ [ "test/data/pos_normal" , "test/data/pos_follow_inodes_normal" ] ,
55+ ]
56+ )
57+ test "Exclude nonexistant paths" do |( paths , expected ) |
58+ tail_check = Fluent ::TailChecker ::TailCheck . new
59+
60+ validated_paths = tail_check . validate_paths ( paths ) . to_a
61+
62+ assert_equal ( expected , validated_paths )
63+ end
64+ end
65+
66+ sub_test_case "Check" do
67+ data ( "No pos_file" , [ [ ] , false , false ] )
68+ data ( "No pos_file with follow_inodes" , [ [ ] , true , false ] )
69+ data ( "Normal" , [ [ "test/data/pos_normal" ] , false , true ] )
70+ data ( "Duplicated unwatched paths" , [ [ "test/data/pos_duplicate_unwatched_path" ] , false , false ] )
71+ data ( "Normal with follow_inodes" , [ [ "test/data/pos_follow_inodes_normal" ] , true , true ] )
72+ data ( "Duplicated unwatched inodes with follow_inodes" , [ [ "test/data/pos_duplicate_unwatched_inode" ] , true , false ] )
73+ data ( "Duplicated unwatched paths with follow_inodes" , [ [ "test/data/pos_duplicate_unwatched_path" ] , true , true ] )
74+ data ( "Normal multiple" , [ [ "test/data/pos_follow_inodes_normal" , "test/data/pos_duplicate_unwatched_path" ] , true , true ] )
75+ data ( "Anomaly multiple" , [ [ "test/data/pos_follow_inodes_normal" , "test/data/pos_duplicate_unwatched_inode" ] , true , false ] )
76+ test "Return false when an anomaly is detected or there is no target" do |( paths , follow_inodes , expected ) |
77+ tail_check = Fluent ::TailChecker ::TailCheck . new
78+ tail_check . instance_variable_set ( :@pos_filepaths , paths )
79+ tail_check . instance_variable_set ( :@follow_inodes , follow_inodes )
80+
81+ result = tail_check . check
82+
83+ assert_equal ( expected , result )
84+ end
1485 end
1586end
0 commit comments