Sha256: f217b138d46e4747df29ed52f3928e8c74602e934be172ea0b469d3a46d25336

Contents?: true

Size: 1.57 KB

Versions: 689

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'
require 'puppet/util/watched_file'
require 'puppet/util/watcher'

describe Puppet::Util::WatchedFile do
  let(:an_absurdly_long_timeout) { Puppet::Util::Watcher::Timer.new(100000) }
  let(:an_immediate_timeout) { Puppet::Util::Watcher::Timer.new(0) }

  it "acts like a string so that it can be used as a filename" do
    watched = Puppet::Util::WatchedFile.new("foo")

    expect(watched.to_str).to eq("foo")
  end

  it "considers the file to be unchanged before the timeout expires" do
    watched = Puppet::Util::WatchedFile.new(a_file_that_doesnt_exist, an_absurdly_long_timeout)

    expect(watched).to_not be_changed
  end

  it "considers a file that is created to be changed" do
    watched_filename = a_file_that_doesnt_exist
    watched = Puppet::Util::WatchedFile.new(watched_filename, an_immediate_timeout)

    create_file(watched_filename)

    expect(watched).to be_changed
  end

  it "considers a missing file to remain unchanged" do
    watched = Puppet::Util::WatchedFile.new(a_file_that_doesnt_exist, an_immediate_timeout)

    expect(watched).to_not be_changed
  end

  it "considers a file that has changed but the timeout is not expired to still be unchanged" do
    watched_filename = a_file_that_doesnt_exist
    watched = Puppet::Util::WatchedFile.new(watched_filename, an_absurdly_long_timeout)

    create_file(watched_filename)

    expect(watched).to_not be_changed
  end

  def create_file(name)
    File.open(name, "wb") { |file| file.puts("contents") }
  end

  def a_file_that_doesnt_exist
    PuppetSpec::Files.tmpfile("watched_file")
  end
end

Version data entries

689 entries across 689 versions & 1 rubygems

Version Path
puppet-8.3.0 spec/unit/util/watched_file_spec.rb
puppet-8.3.0-x86-mingw32 spec/unit/util/watched_file_spec.rb
puppet-8.3.0-x64-mingw32 spec/unit/util/watched_file_spec.rb
puppet-8.3.0-universal-darwin spec/unit/util/watched_file_spec.rb
puppet-8.4.0 spec/unit/util/watched_file_spec.rb
puppet-8.4.0-x86-mingw32 spec/unit/util/watched_file_spec.rb
puppet-8.4.0-x64-mingw32 spec/unit/util/watched_file_spec.rb
puppet-8.4.0-universal-darwin spec/unit/util/watched_file_spec.rb
puppet-7.28.0 spec/unit/util/watched_file_spec.rb
puppet-7.28.0-x86-mingw32 spec/unit/util/watched_file_spec.rb
puppet-7.28.0-x64-mingw32 spec/unit/util/watched_file_spec.rb
puppet-7.28.0-universal-darwin spec/unit/util/watched_file_spec.rb
puppet-8.3.1 spec/unit/util/watched_file_spec.rb
puppet-8.3.1-x86-mingw32 spec/unit/util/watched_file_spec.rb
puppet-8.3.1-x64-mingw32 spec/unit/util/watched_file_spec.rb
puppet-8.3.1-universal-darwin spec/unit/util/watched_file_spec.rb
puppet-7.27.0 spec/unit/util/watched_file_spec.rb
puppet-7.27.0-x86-mingw32 spec/unit/util/watched_file_spec.rb
puppet-7.27.0-x64-mingw32 spec/unit/util/watched_file_spec.rb
puppet-7.27.0-universal-darwin spec/unit/util/watched_file_spec.rb