File: file_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 (58 lines) | stat: -rw-r--r-- 2,202 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
57
58
#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/indirector/file_metadata/file'

describe Puppet::Indirector::FileMetadata::File do
  it "should be registered with the file_metadata indirection" do
    expect(Puppet::Indirector::Terminus.terminus_class(:file_metadata, :file)).to equal(Puppet::Indirector::FileMetadata::File)
  end

  it "should be a subclass of the DirectFileServer terminus" do
    expect(Puppet::Indirector::FileMetadata::File.superclass).to equal(Puppet::Indirector::DirectFileServer)
  end

  describe "when creating the instance for a single found file" do
    before do
      @metadata = Puppet::Indirector::FileMetadata::File.new
      @path = File.expand_path('/my/local')
      @uri = Puppet::Util.path_to_uri(@path).to_s
      @data = mock 'metadata'
      @data.stubs(:collect)
      Puppet::FileSystem.expects(:exist?).with(@path).returns true

      @request = Puppet::Indirector::Request.new(:file_metadata, :find, @uri, nil)
    end

    it "should collect its attributes when a file is found" do
      @data.expects(:collect)

      Puppet::FileServing::Metadata.expects(:new).returns(@data)
      expect(@metadata.find(@request)).to eq(@data)
    end
  end

  describe "when searching for multiple files" do
    before do
      @metadata = Puppet::Indirector::FileMetadata::File.new
      @path = File.expand_path('/my/local')
      @uri = Puppet::Util.path_to_uri(@path).to_s

      @request = Puppet::Indirector::Request.new(:file_metadata, :find, @uri, nil)
    end

    it "should collect the attributes of the instances returned" do
      Puppet::FileSystem.expects(:exist?).with(@path).returns true
      Puppet::FileServing::Fileset.expects(:new).with(@path, @request).returns mock("fileset")
      Puppet::FileServing::Fileset.expects(:merge).returns [["one", @path], ["two", @path]]

      one = mock("one", :collect => nil)
      Puppet::FileServing::Metadata.expects(:new).with(@path, {:relative_path => "one"}).returns one

      two = mock("two", :collect => nil)
      Puppet::FileServing::Metadata.expects(:new).with(@path, {:relative_path => "two"}).returns two

      expect(@metadata.search(@request)).to eq([one, two])
    end
  end
end