~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to spec/unit/indirector/direct_file_server.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080726154345-c03m49twzxewdwjn
Tags: 0.24.5-2
* Fix puppetlast to work with 0.24.5
* Adjust logcheck to match against new log messages in 0.24.5
* Update standards version to 3.8.0 (no changes)
* Update changelog to reduce length of line to make lintian happy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
#
 
3
#  Created by Luke Kanies on 2007-10-24.
 
4
#  Copyright (c) 2007. All rights reserved.
 
5
 
 
6
require File.dirname(__FILE__) + '/../../spec_helper'
 
7
 
 
8
require 'puppet/indirector/direct_file_server'
 
9
 
 
10
describe Puppet::Indirector::DirectFileServer do
 
11
    before :each do
 
12
        Puppet::Indirector::Terminus.stubs(:register_terminus_class)
 
13
        @model = mock 'model'
 
14
        @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
 
15
        Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)
 
16
 
 
17
        @direct_file_class = Class.new(Puppet::Indirector::DirectFileServer) do
 
18
            def self.to_s
 
19
                "Testing::Mytype"
 
20
            end
 
21
        end
 
22
 
 
23
        @server = @direct_file_class.new
 
24
 
 
25
        @uri = "file:///my/local"
 
26
 
 
27
        @request = stub 'request', :key => @uri, :options => {}
 
28
    end
 
29
 
 
30
    describe Puppet::Indirector::DirectFileServer, "when finding a single file" do
 
31
 
 
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
 
35
        end
 
36
 
 
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
 
41
        end
 
42
    end
 
43
 
 
44
    describe Puppet::Indirector::DirectFileServer, "when creating the instance for a single found file" do
 
45
 
 
46
        before do
 
47
            @data = mock 'content'
 
48
            @data.stubs(:collect_attributes)
 
49
            FileTest.expects(:exists?).with("/my/local").returns true
 
50
        end
 
51
 
 
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)
 
55
        end
 
56
 
 
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)
 
60
        end
 
61
 
 
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)
 
65
 
 
66
            @request.stubs(:options).returns(:links => :manage)
 
67
            @server.find(@request)
 
68
        end
 
69
    end
 
70
 
 
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
 
75
        end
 
76
 
 
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)
 
81
        end
 
82
 
 
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)
 
87
        end
 
88
    end
 
89
end