3
# Created by Luke Kanies on 2007-10-24.
4
# Copyright (c) 2007. All rights reserved.
6
require File.dirname(__FILE__) + '/../../spec_helper'
8
require 'puppet/indirector/direct_file_server'
10
describe Puppet::Indirector::DirectFileServer do
12
Puppet::Indirector::Terminus.stubs(:register_terminus_class)
14
@indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
15
Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)
17
@direct_file_class = Class.new(Puppet::Indirector::DirectFileServer) do
23
@server = @direct_file_class.new
25
@uri = "file:///my/local"
27
@request = stub 'request', :key => @uri, :options => {}
30
describe Puppet::Indirector::DirectFileServer, "when finding a single file" do
32
it "should return nil if the file does not exist" do
33
FileTest.expects(:exists?).with("/my/local").returns false
34
@server.find(@request).should be_nil
37
it "should return a Content instance created with the full path to the file if the file exists" do
38
FileTest.expects(:exists?).with("/my/local").returns true
39
@model.expects(:new).returns(:mycontent)
40
@server.find(@request).should == :mycontent
44
describe Puppet::Indirector::DirectFileServer, "when creating the instance for a single found file" do
47
@data = mock 'content'
48
@data.stubs(:collect_attributes)
49
FileTest.expects(:exists?).with("/my/local").returns true
52
it "should create the Content instance with the original key as the key" do
53
@model.expects(:new).with { |key, options| key == @uri }.returns(@data)
54
@server.find(@request)
57
it "should pass the full path to the instance" do
58
@model.expects(:new).with { |key, options| options[:path] == "/my/local" }.returns(@data)
59
@server.find(@request)
62
it "should pass the :links setting on to the created Content instance if the file exists and there is a value for :links" do
63
@model.expects(:new).returns(@data)
64
@data.expects(:links=).with(:manage)
66
@request.stubs(:options).returns(:links => :manage)
67
@server.find(@request)
71
describe Puppet::Indirector::DirectFileServer, "when searching for multiple files" do
72
it "should return nil if the file does not exist" do
73
FileTest.expects(:exists?).with("/my/local").returns false
74
@server.find(@request).should be_nil
77
it "should use :path2instances from the terminus_helper to return instances if the file exists" do
78
FileTest.expects(:exists?).with("/my/local").returns true
79
@server.expects(:path2instances)
80
@server.search(@request)
83
it "should pass the original request to :path2instances" do
84
FileTest.expects(:exists?).with("/my/local").returns true
85
@server.expects(:path2instances).with(@request, "/my/local")
86
@server.search(@request)