summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-23 09:37:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-23 09:37:23 +0000
commite6847d1c559c00f2dcf7d9d3a2e1db56dcecfbaa (patch)
tree0b49f528b89c964229a7392a9c0779ec0db10145 /test
parentbc159ec502dd62f2b194c25357fd9f694b5f3f99 (diff)
test_fileutils.rb: tests for chown
* test/fileutils/fileasserts.rb (assert_ownership_group): new assertion for group ownership. * test/fileutils/test_fileutils.rb (test_chown{,_verbose,_noop}): based on the patch by vajrasky (Vajrasky Kok) at [ruby-core:59281]. [Feature #9286] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/fileutils/fileasserts.rb9
-rw-r--r--test/fileutils/test_fileutils.rb46
2 files changed, 54 insertions, 1 deletions
diff --git a/test/fileutils/fileasserts.rb b/test/fileutils/fileasserts.rb
index c60606ee7f..2cc7e2316b 100644
--- a/test/fileutils/fileasserts.rb
+++ b/test/fileutils/fileasserts.rb
@@ -88,6 +88,15 @@ File modes expected to be equal:
<#{'%0*o' % [width, mode2]}>: "#{file2}"
EOT
end
+
+ def assert_ownership_group(expected, file)
+ actual = File.stat(file).gid
+ assert expected == actual, <<EOT
+File group ownership of "#{file}" unexpected:
+ Expected: <#{expected}>
+ Actual: <#{actual}>
+EOT
+ end
end
end
end
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index c5f8734fea..a30d1ab94d 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -1,6 +1,7 @@
# $Id$
require 'fileutils'
+require 'etc'
require_relative 'fileasserts'
require 'pathname'
require 'tmpdir'
@@ -111,6 +112,7 @@ class TestFileUtils
def setup
@prevdir = Dir.pwd
+ @groups = Process.groups
tmproot = TMPROOT
mymkdir tmproot unless File.directory?(tmproot)
Dir.chdir tmproot
@@ -1052,11 +1054,53 @@ class TestFileUtils
}
end if have_file_perm?
- # FIXME: How can I test this method?
def test_chown
check_singleton :chown
+
+ return unless @groups[1]
+
+ input_group_1 = @groups[0]
+ assert_output_lines([]) {
+ touch 'tmp/a'
+ # integer input for group, nil for user
+ chown nil, input_group_1, 'tmp/a'
+ assert_ownership_group @groups[0], 'tmp/a'
+ }
+
+ input_group_2 = Etc.getgrgid(@groups[1]).name
+ assert_output_lines([]) {
+ touch 'tmp/b'
+ # string input for group, -1 for user
+ chown -1, input_group_2, 'tmp/b'
+ assert_ownership_group @groups[1], 'tmp/b'
+ }
end if have_file_perm?
+ def test_chown_verbose
+ assert_output_lines(["chown :#{@groups[0]} tmp/a1 tmp/a2"]) {
+ touch 'tmp/a1'
+ touch 'tmp/a2'
+ chown nil, @groups[0], ['tmp/a1', 'tmp/a2'], verbose: true
+ assert_ownership_group @groups[0], 'tmp/a1'
+ assert_ownership_group @groups[0], 'tmp/a2'
+ }
+ end if have_file_perm?
+
+ def test_chown_noop
+ return unless @groups[1]
+ assert_output_lines([]) {
+ touch 'tmp/a'
+ chown nil, @groups[0], 'tmp/a', :noop => false
+ assert_ownership_group @groups[0], 'tmp/a'
+ chown nil, @groups[1], 'tmp/a', :noop => true
+ assert_ownership_group @groups[0], 'tmp/a'
+ chown nil, @groups[1], 'tmp/a'
+ assert_ownership_group @groups[1], 'tmp/a'
+ }
+ end if have_file_perm?
+
+ # FIXME: Need to add test for chown with root account
+
# FIXME: How can I test this method?
def test_chown_R
check_singleton :chown_R