File: watcher_spec.rb

package info (click to toggle)
puppet 4.8.2-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,736 kB
  • ctags: 14,616
  • sloc: ruby: 236,754; xml: 1,586; sh: 1,178; lisp: 299; sql: 103; yacc: 72; makefile: 52
file content (56 lines) | stat: -rw-r--r-- 1,725 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /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 initially 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