summaryrefslogtreecommitdiff
path: root/spec/unit/util_spec.rb
AgeCommit message (Collapse)AuthorFilesLines
2011-09-30Merge branch 'file-providers' of https://github.com/joshcooper/puppet into 2.7.xCameron Thomas1-4/+106
Conflicts: lib/puppet/util/adsi.rb spec/unit/util/adsi_spec.rb
2011-09-27Added methods for manipulating URI and file pathsJosh Cooper1-0/+102
Added Puppet::Util.path_to_uri and uri_to_path. These methods will be needed to support Windows file paths as the file 'source' property, metadata, and indirector. The path_to_uri method takes an absolute path and constructs a file URI, e.g. 'file:/foo'. Note this is equivalent to 'file:///foo' as in both cases the authority component of the URI is optional. On Windows local file paths are typically URI-ized as 'file:/C:/foo' (or 'file:///C:/foo'), whereas 'file://host/C:/foo' is used to express UNC paths. The uri_to_path method takes a URI (not necessarily a file URI) and extracts the unescaped path portion. So given a URI of 'file:/foo%20bar', the method returns '/foo bar'. On Windows, this method strips the leading slash from file URIs that contain drive letters. It also converts UNC URIs of the form 'file://host/share/file' to '//host/share/file'
2011-09-27Restrict the absolute path regex to the start of the stringJosh Cooper1-4/+4
Previously the regex used to detect Windows absolute paths only applied the caret to the first part of the regex (the part that matched drive letters). But the parts used to detect UNC paths (\\server\name) and prefixed paths (\\?\C:\foo) were matching any part of the string. And since / and \ are valid path separators on Windows, URIs like puppet://foo/bar (used as file sources) were incorrectly thought to be absolute paths. This commit ensures the absolute path regex is restricted to the start of the string for all cases.
2011-09-14(#8410) Fix child exit status on WindowsJosh Cooper1-9/+14
The Process.waitpid2 method in the win32-process gem returns an array, with the child's exit status as the last element. This is different than ruby's implementation where the last element is a Process::Status object, which has an exitstatus method. As a result, if a child process returned a non-zero exit status on Windows, then Puppet::Util.execute would raise an error while trying to call the exitstatus method on a Fixnum (the actual exit status). This commit ensures we consistently retrieve the exit status across all platforms.
2011-08-24Properly determine file deletion in puppet/unit/util_spec.rbNick Lewis1-2/+2
This test had previously been checking that the path attribute of the Tempfile used for stdout was nil, in order to determine whether or not the file had been deleted. However, on Ruby 1.8.5, a Tempfile's data is not cleared when the file is closed and deleted. Thus, its path wasn't actually nil and it was failing, even though the file had properly been deleted. Now, we just check whether or not the file exists, which will always directly correspond to whether or not the file has been deleted. Reviewed-By: Matt Robinson <matt@puppetlabs.com>
2011-08-24(#8410) Cleanup and fix Windows support in Puppet::Util.executeNick Lewis1-0/+286
The primary change in this commit is fixing the support for Windows in Puppet::Util.execute. However, properly testing this commit required significant refactoring (which was long overdue for this old code) for testability. The functionality for executing on posix and windows was extracted into platform-specific methods, execute_posix and execute_windows. These methods are self-contained and will both return the PID of the child process, which the caller then waits on before reading and returning the output of the command.
2011-08-23(#8410) Add a helper to Puppet::Util to determine absoluteness of a pathNick Lewis1-0/+49
The method Puppet::Util.absolute_path? accepts a path and an optional platform (:windows or :posix) as an argument. If no platform is given, it will default to the local platform. The method will return true if the path provided is absolute on that platform, and false if it is not. This method is also being used in Puppet::Util.which in lieu of testing against a platform-specific regex inline.