Project

General

Profile

Feature #9286 ยป add_unit_test_chown_normal_user.patch

vajrasky (Vajrasky Kok), 12/23/2013 05:40 PM

View differences:

test/fileutils/fileasserts.rb (working copy)
88 88
 <#{'%0*o' % [width, mode2]}>: "#{file2}"
89 89
EOT
90 90
      end
91

  
92
      def assert_ownership_group(expected, file)
93
        actual = File.stat(file).gid
94
        assert expected == actual, <<EOT
95
File group ownership of "#{file}" unexpected:
96
 Expected: <#{'%s' % expected}>
97
   Actual: <#{'%s' % actual}>
98
EOT
99
      end
91 100
    end
92 101
  end
93 102
end
test/fileutils/test_fileutils.rb (working copy)
1 1
# $Id$
2 2

  
3 3
require 'fileutils'
4
require 'etc'
4 5
require_relative 'fileasserts'
5 6
require 'pathname'
6 7
require 'tmpdir'
......
111 112

  
112 113
  def setup
113 114
    @prevdir = Dir.pwd
115
    @groups = Process.groups
114 116
    tmproot = TMPROOT
115 117
    mymkdir tmproot unless File.directory?(tmproot)
116 118
    Dir.chdir tmproot
......
1052 1054
    }
1053 1055
  end if have_file_perm?
1054 1056

  
1055
  # FIXME: How can I test this method?
1056 1057
  def test_chown
1057 1058
    check_singleton :chown
1059

  
1060
    input_group_1 = @groups[0]
1061
    assert_output_lines([]) {
1062
      touch 'tmp/a'
1063
      # integer input for group, nil for user
1064
      chown nil, input_group_1, 'tmp/a'
1065
      assert_ownership_group @groups[0], 'tmp/a'
1066
    }
1067

  
1068
    if @groups[1]
1069
      input_group_2 = Etc.getgrgid(@groups[1]).name
1070
      assert_output_lines([]) {
1071
        touch 'tmp/b'
1072
        # string input for group, -1 for user
1073
        chown -1, input_group_2, 'tmp/b'
1074
        assert_ownership_group @groups[1], 'tmp/b'
1075
      }
1076
    end
1058 1077
  end if have_file_perm?
1059 1078

  
1079
  def test_chown_verbose
1080
    assert_output_lines(["chown :#{@groups[0]} tmp/a1 tmp/a2"]) {
1081
      touch 'tmp/a1'
1082
      touch 'tmp/a2'
1083
      chown nil, @groups[0], ['tmp/a1', 'tmp/a2'], :verbose => true
1084
      assert_ownership_group @groups[0], 'tmp/a1'
1085
      assert_ownership_group @groups[0], 'tmp/a2'
1086
    }
1087
  end if have_file_perm?
1088

  
1089
  def test_chown_noop
1090
    if @groups[1]
1091
      assert_output_lines([]) {
1092
        touch 'tmp/a'
1093
        chown nil, @groups[0], 'tmp/a', :noop => false
1094
        assert_ownership_group @groups[0], 'tmp/a'
1095
        chown nil, @groups[1], 'tmp/a', :noop => true
1096
        assert_ownership_group @groups[0], 'tmp/a'
1097
        chown nil, @groups[1], 'tmp/a'
1098
        assert_ownership_group @groups[1], 'tmp/a'
1099
      }
1100
    end
1101
  end if have_file_perm?
1102

  
1103
  # FIXME: Need to add test for chown with root account
1104

  
1060 1105
  # FIXME: How can I test this method?
1061 1106
  def test_chown_R
1062 1107
    check_singleton :chown_R