Sha256: e740ed4cec0009de0ad977cf3551d7dfe59782fb043e6a8099c1c4d0db92ac8c

Contents?: true

Size: 1.68 KB

Versions: 57

Compression:

Stored size: 1.68 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/util/watcher'

describe Puppet::Util::Watcher do
  describe "the common file ctime watcher" do
    FakeStat = Struct.new(:ctime)

    def ctime(time)
      FakeStat.new(time)
    end

    let(:filename) { "fake" }

    def after_reading_the_sequence(initial, *results)
      expectation = Puppet::FileSystem.expects(:stat).with(filename).at_least(1)
      ([initial] + results).each do |result|
        expectation = if result.is_a? Class
                        expectation.raises(result)
                      else
                        expectation.returns(result)
                      end.then
      end

      watcher = Puppet::Util::Watcher::Common.file_ctime_change_watcher(filename)
      results.size.times { watcher = watcher.next_reading }

      watcher
    end

    it "is intially unchanged" do
      expect(after_reading_the_sequence(ctime(20))).to_not be_changed
    end

    it "has not changed if a section of the file path continues to not exist" do
      expect(after_reading_the_sequence(Errno::ENOTDIR, Errno::ENOTDIR)).to_not be_changed
    end

    it "has not changed if the file continues to not exist" do
      expect(after_reading_the_sequence(Errno::ENOENT, Errno::ENOENT)).to_not be_changed
    end

    it "has changed if the file is created" do
      expect(after_reading_the_sequence(Errno::ENOENT, ctime(20))).to be_changed
    end

    it "is marked as changed if the file is deleted" do
      expect(after_reading_the_sequence(ctime(20), Errno::ENOENT)).to be_changed
    end

    it "is marked as changed if the file modified" do
      expect(after_reading_the_sequence(ctime(20), ctime(21))).to be_changed
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
puppet-3.8.7 spec/unit/util/watcher_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.6 spec/unit/util/watcher_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.5 spec/unit/util/watcher_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.4 spec/unit/util/watcher_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.3 spec/unit/util/watcher_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.2 spec/unit/util/watcher_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/util/watcher_spec.rb
puppet-3.8.1 spec/unit/util/watcher_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/util/watcher_spec.rb