aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppet.com>2018-06-27 22:33:00 -0700
committerJosh Cooper <josh@puppet.com>2018-06-27 22:33:00 -0700
commit1294290d6045fdd383a17cb45039b671ab954f05 (patch)
tree92ec08eff71c26d5f43fb19fb93861ae2821ae1c
parent69f941224a43275896218807fd91c8e5b912f8d1 (diff)
downloadpuppet-augeas_core-1294290d6045fdd383a17cb45039b671ab954f05.tar.gz
puppet-augeas_core-1294290d6045fdd383a17cb45039b671ab954f05.tar.bz2
Update for pdk test unit
Add tmpfile helper
-rw-r--r--spec/unit/provider/augeas/augeas_spec.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/spec/unit/provider/augeas/augeas_spec.rb b/spec/unit/provider/augeas/augeas_spec.rb
index 51a734d..f7358ba 100644
--- a/spec/unit/provider/augeas/augeas_spec.rb
+++ b/spec/unit/provider/augeas/augeas_spec.rb
@@ -22,6 +22,23 @@ describe provider_class do
File.expand_path(File.join(File.dirname(__FILE__), '../../../fixtures/unit/provider/augeas/augeas'))
end
+ def tmpfile(name)
+ Puppet::FileSystem.expand_path(make_tmpname(name, nil).encode(Encoding::UTF_8), Dir.tmpdir)
+ end
+
+ # Copied from ruby 2.4 source
+ def make_tmpname((prefix, suffix), n)
+ prefix = (String.try_convert(prefix) or
+ raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
+ suffix &&= (String.try_convert(suffix) or
+ raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
+ t = Time.now.strftime("%Y%m%d")
+ path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}".dup
+ path << "-#{n}" if n
+ path << suffix if suffix
+ path
+ end
+
describe "command parsing" do
it "should break apart a single line into three tokens and clean up the context" do
@resource[:context] = "/context"
@@ -821,8 +838,8 @@ describe provider_class do
it "should not clobber the file if it's a symlink" do
Puppet::Util::Storage.stubs(:store)
- link = Tempfile.new('link')
- target = Tempfile.new('target')
+ link = tmpfile('link')
+ target = tmpfile('target')
FileUtils.touch(target)
Puppet::FileSystem.symlink(target, link)