|
6 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | # you may not use this file except in compliance with the License. |
8 | 8 | # You may obtain a copy of the License at |
9 | | -# |
| 9 | +# |
10 | 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
11 | | -# |
| 11 | +# |
12 | 12 | # Unless required by applicable law or agreed to in writing, software |
13 | 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
14 | 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
26 | 26 | @io = mock("IO", { :print => true, :close => true }) |
27 | 27 | File.stub!(:open).and_return(@io) |
28 | 28 | end |
29 | | - |
| 29 | + |
30 | 30 | it "should create the directories leading up to bang" do |
31 | 31 | File.stub!(:directory?).and_return(false) |
32 | 32 | Dir.should_receive(:mkdir).with("/tmp").and_return(true) |
|
35 | 35 | Dir.should_not_receive(:mkdir).with("/tmp/foo/whiz/bang").and_return(true) |
36 | 36 | Chef::FileCache.store("whiz/bang", "I found a poop") |
37 | 37 | end |
38 | | - |
| 38 | + |
39 | 39 | it "should create a file at /tmp/foo/whiz/bang" do |
40 | 40 | File.should_receive(:open).with("/tmp/foo/whiz/bang", "w").and_return(@io) |
41 | 41 | Chef::FileCache.store("whiz/bang", "I found a poop") |
42 | 42 | end |
43 | | - |
| 43 | + |
44 | 44 | it "should print the contents to the file" do |
45 | 45 | @io.should_receive(:print).with("I found a poop") |
46 | 46 | Chef::FileCache.store("whiz/bang", "I found a poop") |
47 | 47 | end |
48 | | - |
| 48 | + |
49 | 49 | it "should close the file" do |
50 | 50 | @io.should_receive(:close) |
51 | 51 | Chef::FileCache.store("whiz/bang", "I found a poop") |
|
61 | 61 | File.stub!(:exists?).and_return(true) |
62 | 62 | File.stub!(:read).and_return("I found a poop") |
63 | 63 | end |
64 | | - |
| 64 | + |
65 | 65 | it "should find the full path to whiz/bang" do |
66 | 66 | File.should_receive(:read).with("/tmp/foo/whiz/bang").and_return(true) |
67 | 67 | Chef::FileCache.load('whiz/bang') |
68 | 68 | end |
69 | | - |
| 69 | + |
70 | 70 | it "should raise a Chef::Exceptions::FileNotFound if the file doesn't exist" do |
71 | 71 | File.stub!(:exists?).and_return(false) |
72 | 72 | lambda { Chef::FileCache.load('whiz/bang') }.should raise_error(Chef::Exceptions::FileNotFound) |
73 | 73 | end |
74 | 74 | end |
75 | | - |
| 75 | + |
76 | 76 | describe Chef::FileCache, "delete method" do |
77 | 77 | before(:each) do |
78 | 78 | Chef::Config[:file_cache_path] = "/tmp/foo" |
|
81 | 81 | File.stub!(:exists?).and_return(true) |
82 | 82 | File.stub!(:unlink).and_return(true) |
83 | 83 | end |
84 | | - |
| 84 | + |
85 | 85 | it "should unlink the full path to whiz/bang" do |
86 | 86 | File.should_receive(:unlink).with("/tmp/foo/whiz/bang").and_return(true) |
87 | 87 | Chef::FileCache.delete("whiz/bang") |
88 | 88 | end |
89 | | - |
| 89 | + |
90 | 90 | end |
91 | 91 |
|
92 | 92 | describe Chef::FileCache, "list method" do |
93 | 93 | before(:each) do |
94 | 94 | Chef::Config[:file_cache_path] = "/tmp/foo" |
95 | | - Dir.stub!(:[]).and_return(["/tmp/foo/whiz/bang", "/tmp/foo/snappy/patter"]) |
| 95 | + Dir.stub!(:[]).with(File.join(Chef::Config[:file_cache_path], '**', '*')).and_return(["/tmp/foo/whiz/bang", "/tmp/foo/snappy/patter"]) |
| 96 | + Dir.stub!(:[]).with(Chef::Config[:file_cache_path]).and_return(["/tmp/foo"]) |
96 | 97 | File.stub!(:file?).and_return(true) |
97 | 98 | end |
98 | | - |
| 99 | + |
99 | 100 | it "should return the relative paths" do |
100 | 101 | Chef::FileCache.list.should eql([ "whiz/bang", "snappy/patter" ]) |
101 | 102 | end |
|
105 | 106 | before(:each) do |
106 | 107 | Chef::Config[:file_cache_path] = "/tmp/foo" |
107 | 108 | end |
108 | | - |
| 109 | + |
109 | 110 | it "should check the full path to the file" do |
110 | 111 | File.should_receive(:exists?).with("/tmp/foo/whiz/bang") |
111 | 112 | Chef::FileCache.has_key?("whiz/bang") |
112 | 113 | end |
113 | | - |
| 114 | + |
114 | 115 | it "should return true if the file exists" do |
115 | 116 | File.stub!(:exists?).and_return(true) |
116 | 117 | Chef::FileCache.has_key?("whiz/bang").should eql(true) |
117 | 118 | end |
118 | | - |
| 119 | + |
119 | 120 | it "should return false if the file does not exist" do |
120 | 121 | File.stub!(:exists?).and_return(false) |
121 | 122 | Chef::FileCache.has_key?("whiz/bang").should eql(false) |
|
0 commit comments