diff options
| author | Paul Buetow <paul@buetow.org> | 2025-02-26 11:28:24 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-02-26 11:28:24 +0200 |
| commit | b394011ce33bd6116bb7d27520d5adea27310862 (patch) | |
| tree | 511c7eebf89c6909eaa8b36f4c1a452875b90a85 | |
| parent | 37eb90aebd8b26508d60f4ec623ae6192df5c09d (diff) | |
add mode test
| -rw-r--r-- | test/lib/dslkeywords/file_test.rb | 9 | ||||
| -rw-r--r-- | test/lib/dslkeywords/mode_test.rb | 49 |
2 files changed, 49 insertions, 9 deletions
diff --git a/test/lib/dslkeywords/file_test.rb b/test/lib/dslkeywords/file_test.rb index 0a95e7e..35a0f21 100644 --- a/test/lib/dslkeywords/file_test.rb +++ b/test/lib/dslkeywords/file_test.rb @@ -22,15 +22,6 @@ class RCMFileTest < Minitest::Test assert_equal text, File.read(FILE_PATH) end - # def test_file_mode - # configure_from_scratch do - # file FILE_PATH do - # mode 661 - # 'content' - # end - # end - # end - def test_create_file_from_array arr = %w[Hello World and Hello Universe] configure_from_scratch do diff --git a/test/lib/dslkeywords/mode_test.rb b/test/lib/dslkeywords/mode_test.rb new file mode 100644 index 0000000..4102c74 --- /dev/null +++ b/test/lib/dslkeywords/mode_test.rb @@ -0,0 +1,49 @@ +require 'minitest/autorun' +require 'fileutils' + +require_relative '../../../lib/dsl' + +class RCMModeTest < Minitest::Test + FILE1_PATH = './.file_test1.rcmtmp'.freeze + FILE2_PATH = './.file_test2.rcmtmp'.freeze + SYMLINK_PATH = './.symlink_test.rcmtmp'.freeze + SYMLINK_TARGET_PATH = './.symlink_target_test.rcmtmp'.freeze + DIR_PATH = './.dir_test.rcmtmp'.freeze + + Minitest.after_run do + File.unlink(FILE1_PATH) if File.file?(FILE1_PATH) + File.unlink(FILE2_PATH) if File.file?(FILE2_PATH) + File.unlink(SYMLINK_PATH) if File.file?(SYMLINK_PATH) + File.unlink(SYMLINK_TARGET_PATH) if File.file?(SYMLINK_TARGET_PATH) + FileUtils.rm_r(DIR_PATH) if File.directory?(DIR_PATH) + end + + def test_file_mode + configure_from_scratch do + touch FILE1_PATH do + mode 0o600 + end + file FILE2_PATH do + mode 0o644 + 'content' + end + directory DIR_PATH do + mode 0o705 + end + + touch SYMLINK_TARGET_PATH do + mode 0o777 + end + symlink SYMLINK_PATH do + mode 0o000 # mode won't do here anything! + requires touch SYMLINK_TARGET_PATH + SYMLINK_TARGET_PATH + end + end + + assert_equal 0o600, File.stat(FILE1_PATH).mode.to_s(8).split('')[-4..-1].join.to_i(8) + assert_equal 0o644, File.stat(FILE2_PATH).mode.to_s(8).split('')[-4..-1].join.to_i(8) + assert_equal 0o705, File.stat(DIR_PATH).mode.to_s(8).split('')[-4..-1].join.to_i(8) + assert_equal 0o777, File.stat(SYMLINK_TARGET_PATH).mode.to_s(8).split('')[-4..-1].join.to_i(8) + end +end |
