blob: e53b48d69c4a93f0e138bd3a11d45d50adf5c289 (
plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/usr/bin/env rspec
#
# Created by Luke Kanies on 2007-10-19.
# Copyright (c) 2007. All rights reserved.
require 'spec_helper'
require 'puppet/indirector/file_content/file'
describe Puppet::Indirector::DirectFileServer, " when interacting with the filesystem and the model" do
before do
# We just test a subclass, since it's close enough.
@terminus = Puppet::Indirector::FileContent::File.new
@filepath = "/path/to/my/file"
end
it "should return an instance of the model" do
FileTest.expects(:exists?).with(@filepath).returns(true)
@terminus.find(@terminus.indirection.request(:find, "file://host#{@filepath}")).should be_instance_of(Puppet::FileServing::Content)
end
it "should return an instance capable of returning its content" do
FileTest.expects(:exists?).with(@filepath).returns(true)
File.stubs(:lstat).with(@filepath).returns(stub("stat", :ftype => "file"))
File.expects(:read).with(@filepath).returns("my content")
instance = @terminus.find(@terminus.indirection.request(:find, "file://host#{@filepath}"))
instance.content.should == "my content"
end
end
describe Puppet::Indirector::DirectFileServer, " when interacting with FileServing::Fileset and the model" do
before do
@terminus = Puppet::Indirector::FileContent::File.new
@path = Tempfile.new("direct_file_server_testing")
path = @path.path
@path.close!
@path = path
Dir.mkdir(@path)
File.open(File.join(@path, "one"), "w") { |f| f.print "one content" }
File.open(File.join(@path, "two"), "w") { |f| f.print "two content" }
@request = @terminus.indirection.request(:search, "file:///#{@path}", :recurse => true)
end
after do
system("rm -rf #{@path}")
end
it "should return an instance for every file in the fileset" do
result = @terminus.search(@request)
result.should be_instance_of(Array)
result.length.should == 3
result.each { |r| r.should be_instance_of(Puppet::FileServing::Content) }
end
it "should return instances capable of returning their content" do
@terminus.search(@request).each do |instance|
case instance.full_path
when /one/; instance.content.should == "one content"
when /two/; instance.content.should == "two content"
when @path
else
raise "No valid key for #{instance.path.inspect}"
end
end
end
end
|