@@ -984,11 +984,12 @@ def increment_counter_in_multiple_processes(file, num_procs, options)
984
984
end
985
985
986
986
it 'preserves file ownership' do
987
- allow ( Puppet :: FileSystem ) . to receive ( :lstat )
988
- . with ( Puppet :: FileSystem . pathname ( dest ) )
989
- . and_return ( double ( uid : 1 , gid : 2 ) )
987
+ FileUtils . touch ( dest )
988
+ allow ( File ) . to receive ( :lstat ) . and_call_original
989
+ allow ( File ) . to receive ( :lstat ) . with ( Pathname . new ( dest ) ) . and_return ( double ( uid : 1 , gid : 2 , 'directory?' : false ) )
990
990
991
- expect ( FileUtils ) . to receive ( :chown ) . with ( 1 , 2 , /#{ dest } / )
991
+ allow ( File ) . to receive ( :chown ) . and_call_original
992
+ expect ( FileUtils ) . to receive ( :chown ) . with ( 1 , 2 , any_args )
992
993
993
994
Puppet ::FileSystem . replace_file ( dest , 0644 ) { |f | f . write ( content ) }
994
995
end
@@ -1163,4 +1164,33 @@ def increment_counter_in_multiple_processes(file, num_procs, options)
1163
1164
expect ( File . mtime ( dest ) ) . to be_within ( 1 ) . of ( tomorrow )
1164
1165
end
1165
1166
end
1167
+
1168
+ context '#chmod' do
1169
+ let ( :dest ) { tmpfile ( 'abs_file' ) }
1170
+
1171
+ it "changes the mode given an absolute string" do
1172
+ Puppet ::FileSystem . touch ( dest )
1173
+ Puppet ::FileSystem . chmod ( 0644 , dest )
1174
+ expect ( File . stat ( dest ) . mode & 0777 ) . to eq ( 0644 )
1175
+ end
1176
+
1177
+ it "returns true if given an absolute pathname" do
1178
+ Puppet ::FileSystem . touch ( dest )
1179
+ Puppet ::FileSystem . chmod ( 0644 , Pathname . new ( dest ) )
1180
+ expect ( File . stat ( dest ) . mode & 0777 ) . to eq ( 0644 )
1181
+ end
1182
+
1183
+ it "raises if the file doesn't exist" do
1184
+ klass = Puppet ::Util ::Platform . windows? ? Puppet ::Error : Errno ::ENOENT
1185
+ expect {
1186
+ Puppet ::FileSystem . chmod ( 0644 , dest )
1187
+ } . to raise_error ( klass )
1188
+ end
1189
+
1190
+ it "raises ArgumentError if dest is invalid" do
1191
+ expect {
1192
+ Puppet ::FileSystem . chmod ( 0644 , nil )
1193
+ } . to raise_error ( ArgumentError , /expected Pathname, got: 'NilClass'/ )
1194
+ end
1195
+ end
1166
1196
end
0 commit comments