@@ -779,7 +779,24 @@ def parse_system(text)
779
779
end
780
780
end
781
781
782
- def run_and_check ( d , symlink_path )
782
+ test 'relative symlink' do
783
+ omit "Windows doesn't support symlinks" if Fluent . windows?
784
+
785
+ conf = CONFIG + %[
786
+ symlink_path #{ SYMLINK_PATH }
787
+ symlink_path_use_relative true
788
+ ]
789
+ symlink_path = "#{ SYMLINK_PATH } "
790
+
791
+ d = create_driver ( conf )
792
+ begin
793
+ run_and_check ( d , symlink_path , relative_symlink = true )
794
+ ensure
795
+ FileUtils . rm_rf ( symlink_path )
796
+ end
797
+ end
798
+
799
+ def run_and_check ( d , symlink_path , relative_symlink = false )
783
800
d . run ( default_tag : 'tag' ) do
784
801
es = Fluent ::OneEventStream . new ( event_time ( "2011-01-02 13:14:15 UTC" ) , { "a" => 1 } )
785
802
d . feed ( es )
@@ -794,7 +811,14 @@ def run_and_check(d, symlink_path)
794
811
assert File . exist? ( symlink_path )
795
812
796
813
meta = d . instance . metadata ( 'tag' , event_time ( "2011-01-03 14:15:16 UTC" ) , { } )
797
- assert_equal d . instance . buffer . instance_eval { @stage [ meta ] . path } , File . readlink ( symlink_path )
814
+ if relative_symlink
815
+ target_path = d . instance . buffer . instance_eval { @stage [ meta ] . path }
816
+ link_target = File . readlink ( symlink_path )
817
+ expected_path = Pathname . new ( target_path ) . relative_path_from ( Pathname . new ( File . dirname ( symlink_path ) ) ) . to_s
818
+ assert_equal expected_path , link_target
819
+ else
820
+ assert_equal d . instance . buffer . instance_eval { @stage [ meta ] . path } , File . readlink ( symlink_path )
821
+ end
798
822
end
799
823
end
800
824
end
0 commit comments