add_unit_test_chown_R.patch

Vajrasky Kok, 01/08/2014 07:08 PM

Download (3.96 KB)

View differences:

test/fileutils/test_fileutils.rb (working copy)
1145 1145
      }
1146 1146
    end
1147 1147

  
1148
    def test_chown_R
1149
      check_singleton :chown_R
1150

  
1151
      return unless @groups[1]
1152

  
1153
      input_group_1 = @groups[0]
1154
      input_group_2 = @groups[1]
1155
      assert_output_lines([]) {
1156
        list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
1157
        mkdir_p 'tmp/dir/a/b/c'
1158
        touch 'tmp/d'
1159
        # string input
1160
        chown_R nil, input_group_1, 'tmp/dir'
1161
        list.each {|dir|
1162
          assert_ownership_group @groups[0], dir
1163
        }
1164
        chown_R nil, input_group_1, 'tmp/d'
1165
        assert_ownership_group @groups[0], 'tmp/d'
1166
        # list input
1167
        chown_R nil, input_group_2, ['tmp/dir', 'tmp/d']
1168
        list += ['tmp/d']
1169
        list.each {|dir|
1170
          assert_ownership_group @groups[1], dir
1171
        }
1172
      }
1173
    end
1174

  
1175
    def test_chown_R_verbose
1176
      assert_output_lines(["chown -R :#{@groups[0]} tmp/dir tmp/d"]) {
1177
        list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
1178
        mkdir_p 'tmp/dir/a/b/c'
1179
        touch 'tmp/d'
1180
        chown_R nil, @groups[0], ['tmp/dir', 'tmp/d'], :verbose => true
1181
        list.each {|dir|
1182
          assert_ownership_group @groups[0], dir
1183
        }
1184
      }
1185
    end
1186

  
1187
    def test_chown_R_noop
1188
      return unless @groups[1]
1189

  
1190
      assert_output_lines([]) {
1191
        list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
1192
        mkdir_p 'tmp/dir/a/b/c'
1193
        chown_R nil, @groups[0], 'tmp/dir', :noop => false
1194
        list.each {|dir|
1195
          assert_ownership_group @groups[0], dir
1196
        }
1197
        chown_R nil, @groups[1], 'tmp/dir', :noop => true
1198
        list.each {|dir|
1199
          assert_ownership_group @groups[0], dir
1200
        }
1201
      }
1202
    end
1203

  
1204
    def test_chown_R_force
1205
      assert_output_lines([]) {
1206
        list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
1207
        mkdir_p 'tmp/dir/a/b/c'
1208
        assert_raise_with_message(Errno::ENOENT, /No such file or directory/) {
1209
            chown_R nil, @groups[0], ['tmp/dir', 'invalid'], :force => false
1210
        }
1211
        chown_R nil, @groups[0], ['tmp/dir', 'invalid'], :force => true
1212
        list.each {|dir|
1213
          assert_ownership_group @groups[0], dir
1214
        }
1215
      }
1216
    end
1217

  
1148 1218
    if root_in_posix?
1149 1219
      def test_chown_with_root
1150 1220
        uid_1, uid_2 = distinct_uids(2)
......
1164 1234
          }
1165 1235
        }
1166 1236
      end
1237

  
1238
      def test_chown_R_with_root
1239
        uid_1, uid_2 = distinct_uids(2)
1240
        return unless uid_1 and uid_2
1241

  
1242
        assert_output_lines([]) {
1243
          list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
1244
          mkdir_p 'tmp/dir/a/b/c'
1245
          touch 'tmp/d'
1246
          # string input
1247
          chown_R uid_1, nil, 'tmp/dir'
1248
          list.each {|dir|
1249
            assert_ownership_user uid_1, dir
1250
          }
1251
          chown_R uid_1, nil, 'tmp/d'
1252
          assert_ownership_user uid_1, 'tmp/d'
1253
          # list input
1254
          chown_R uid_2, nil, ['tmp/dir', 'tmp/d']
1255
          list += ['tmp/d']
1256
          list.each {|dir|
1257
            assert_ownership_user uid_2, dir
1258
          }
1259
        }
1260
      end
1167 1261
    else
1168 1262
      def test_chown_without_permission
1169 1263
        uid_1, uid_2 = distinct_uids(2)
......
1175 1269
          chown uid_2, nil, 'tmp/a'
1176 1270
        }
1177 1271
      end
1272

  
1273
      def test_chown_R_without_permission
1274
        uid_1, uid_2 = distinct_uids(2)
1275
        return unless uid_1 and uid_2
1276

  
1277
        touch 'tmp/a'
1278
        exception = assert_raise(Errno::EPERM) {
1279
          chown_R uid_1, nil, 'tmp/a'
1280
          chown_R uid_2, nil, 'tmp/a'
1281
        }
1282
      end
1178 1283
    end
1179 1284
  end
1180 1285

  
1181
  # FIXME: How can I test this method?
1182
  def test_chown_R
1183
    check_singleton :chown_R
1184
  end if have_file_perm?
1185

  
1186 1286
  def test_copy_entry
1187 1287
    check_singleton :copy_entry
1188 1288