|
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. |
|
22 | 22 | @node = Chef::Node.new |
23 | 23 | @run_context = Chef::RunContext.new(@node, {}) |
24 | 24 | @new_resource = Chef::Resource::Package.new("dev-util/git") |
| 25 | + @new_resource_without_category = Chef::Resource::Package.new("git") |
25 | 26 | @current_resource = Chef::Resource::Package.new("dev-util/git") |
26 | | - |
| 27 | + |
27 | 28 | @provider = Chef::Provider::Package::Portage.new(@new_resource, @run_context) |
28 | 29 | Chef::Resource::Package.stub!(:new).and_return(@current_resource) |
29 | | - |
30 | | - ::File.stub!(:exists?).and_return(true) |
31 | 30 | end |
32 | | - |
| 31 | + |
33 | 32 | describe "when determining the current state of the package" do |
34 | | - |
| 33 | + |
35 | 34 | it "should create a current resource with the name of new_resource" do |
36 | | - ::Dir.stub!(:entries).and_return(["git-1.0.0"]) |
| 35 | + ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0"]) |
37 | 36 | Chef::Resource::Package.should_receive(:new).and_return(@current_resource) |
38 | 37 | @provider.load_current_resource |
39 | 38 | end |
40 | | - |
| 39 | + |
41 | 40 | it "should set the current resource package name to the new resource package name" do |
42 | | - ::Dir.stub!(:entries).and_return(["git-1.0.0"]) |
| 41 | + ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0"]) |
43 | 42 | @current_resource.should_receive(:package_name).with(@new_resource.package_name) |
44 | 43 | @provider.load_current_resource |
45 | 44 | end |
46 | | - |
| 45 | + |
47 | 46 | it "should return a current resource with the correct version if the package is found" do |
48 | | - ::Dir.stub!(:entries).and_return(["git-foobar-0.9", "git-1.0.0"]) |
| 47 | + ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-foobar-0.9", "/var/db/pkg/dev-util/git-1.0.0"]) |
49 | 48 | @provider.load_current_resource |
50 | 49 | @provider.current_resource.version.should == "1.0.0" |
51 | 50 | end |
52 | 51 |
|
53 | 52 | it "should return a current resource with the correct version if the package is found with revision" do |
54 | | - ::Dir.stub!(:entries).and_return(["git-1.0.0-r1"]) |
| 53 | + ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0-r1"]) |
55 | 54 | @provider.load_current_resource |
56 | 55 | @provider.current_resource.version.should == "1.0.0-r1" |
57 | 56 | end |
58 | | - |
| 57 | + |
59 | 58 | it "should return a current resource with a nil version if the package is not found" do |
60 | | - ::Dir.stub!(:entries).and_return(["notgit-1.0.0"]) |
| 59 | + ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/notgit-1.0.0"]) |
61 | 60 | @provider.load_current_resource |
62 | 61 | @provider.current_resource.version.should be_nil |
63 | 62 | end |
64 | 63 |
|
| 64 | + it "should return a package name match from /var/db/pkg/* if a category isn't specified and a match is found" do |
| 65 | + ::Dir.stub!(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/git-foobar-0.9", "/var/db/pkg/dev-util/git-1.0.0"]) |
| 66 | + @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) |
| 67 | + @provider.load_current_resource |
| 68 | + @provider.current_resource.version.should == "1.0.0" |
| 69 | + end |
| 70 | + |
| 71 | + it "should return a current resource with a nil version if a category isn't specified and a name match from /var/db/pkg/* is not found" do |
| 72 | + ::Dir.stub!(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/notgit-1.0.0"]) |
| 73 | + @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) |
| 74 | + @provider.load_current_resource |
| 75 | + @provider.current_resource.version.should be_nil |
| 76 | + end |
| 77 | + |
| 78 | + it "should throw an exception if a category isn't specified and multiple packages are found" do |
| 79 | + ::Dir.stub!(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0", "/var/db/pkg/funny-words/git-1.0.0"]) |
| 80 | + @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) |
| 81 | + lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) |
| 82 | + end |
65 | 83 | end |
66 | | - |
| 84 | + |
67 | 85 | describe "once the state of the package is known" do |
68 | 86 |
|
69 | 87 | describe Chef::Provider::Package::Portage, "candidate_version" do |
70 | | - it "should return the candidate_version variable if already setup" do |
| 88 | + it "should return the candidate_version variable if already set" do |
71 | 89 | @provider.candidate_version = "1.0.0" |
72 | 90 | @provider.should_not_receive(:popen4) |
73 | 91 | @provider.candidate_version |
74 | 92 | end |
75 | 93 |
|
76 | | - it "should lookup the candidate_version if the variable is not already set" do |
77 | | - @status = mock("Status", :exitstatus => 0) |
| 94 | + it "should throw an exception if the exitstatus is not 0" do |
| 95 | + @status = mock("Status", :exitstatus => 1) |
78 | 96 | @provider.stub!(:popen4).and_return(@status) |
79 | | - @provider.should_receive(:popen4) |
80 | | - @provider.candidate_version |
| 97 | + lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) |
81 | 98 | end |
82 | 99 |
|
83 | | - it "should throw and exception if the exitstatus is not 0" do |
84 | | - @status = mock("Status", :exitstatus => 1) |
85 | | - @provider.stub!(:popen4).and_return(@status) |
| 100 | + it "should find the candidate_version if a category is specifed and there are no duplicates" do |
| 101 | + output = <<EOF |
| 102 | +Searching... |
| 103 | +[ Results for search key : git ] |
| 104 | +[ Applications found : 14 ] |
| 105 | +
|
| 106 | +* app-misc/digitemp [ Masked ] |
| 107 | + Latest version available: 3.5.0 |
| 108 | + Latest version installed: [ Not Installed ] |
| 109 | + Size of files: 261 kB |
| 110 | + Homepage: http://www.digitemp.com/ http://www.ibutton.com/ |
| 111 | + Description: Temperature logging and reporting using Dallas Semiconductor's iButtons and 1-Wire protocol |
| 112 | + License: GPL-2 |
| 113 | +
|
| 114 | +* dev-util/git |
| 115 | + Latest version available: 1.6.0.6 |
| 116 | + Latest version installed: ignore |
| 117 | + Size of files: 2,725 kB |
| 118 | + Homepage: http://git.or.cz/ |
| 119 | + Description: GIT - the stupid content tracker, the revision control system heavily used by the Linux kernel team |
| 120 | + License: GPL-2 |
| 121 | +
|
| 122 | +* dev-util/gitosis [ Masked ] |
| 123 | + Latest version available: 0.2_p20080825 |
| 124 | + Latest version installed: [ Not Installed ] |
| 125 | + Size of files: 31 kB |
| 126 | + Homepage: http://eagain.net/gitweb/?p=gitosis.git;a=summary |
| 127 | + Description: gitosis -- software for hosting git repositories |
| 128 | + License: GPL-2 |
| 129 | +EOF |
| 130 | + |
| 131 | + @status = mock("Status", :exitstatus => 0) |
| 132 | + @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) |
| 133 | + @provider.candidate_version.should == "1.6.0.6" |
| 134 | + end |
| 135 | + |
| 136 | + it "should find the candidate_version if a category is not specifed and there are no duplicates" do |
| 137 | + output = <<EOF |
| 138 | +Searching... |
| 139 | +[ Results for search key : git ] |
| 140 | +[ Applications found : 14 ] |
| 141 | +
|
| 142 | +* app-misc/digitemp [ Masked ] |
| 143 | + Latest version available: 3.5.0 |
| 144 | + Latest version installed: [ Not Installed ] |
| 145 | + Size of files: 261 kB |
| 146 | + Homepage: http://www.digitemp.com/ http://www.ibutton.com/ |
| 147 | + Description: Temperature logging and reporting using Dallas Semiconductor's iButtons and 1-Wire protocol |
| 148 | + License: GPL-2 |
| 149 | +
|
| 150 | +* dev-util/git |
| 151 | + Latest version available: 1.6.0.6 |
| 152 | + Latest version installed: ignore |
| 153 | + Size of files: 2,725 kB |
| 154 | + Homepage: http://git.or.cz/ |
| 155 | + Description: GIT - the stupid content tracker, the revision control system heavily used by the Linux kernel team |
| 156 | + License: GPL-2 |
| 157 | +
|
| 158 | +* dev-util/gitosis [ Masked ] |
| 159 | + Latest version available: 0.2_p20080825 |
| 160 | + Latest version installed: [ Not Installed ] |
| 161 | + Size of files: 31 kB |
| 162 | + Homepage: http://eagain.net/gitweb/?p=gitosis.git;a=summary |
| 163 | + Description: gitosis -- software for hosting git repositories |
| 164 | + License: GPL-2 |
| 165 | +EOF |
| 166 | + |
| 167 | + @status = mock("Status", :exitstatus => 0) |
| 168 | + @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) |
| 169 | + @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) |
| 170 | + @provider.candidate_version.should == "1.6.0.6" |
| 171 | + end |
| 172 | + |
| 173 | + it "should throw an exception if a category is not specified and there are duplicates" do |
| 174 | + output = <<EOF |
| 175 | +Searching... |
| 176 | +[ Results for search key : git ] |
| 177 | +[ Applications found : 14 ] |
| 178 | +
|
| 179 | +* app-misc/digitemp [ Masked ] |
| 180 | + Latest version available: 3.5.0 |
| 181 | + Latest version installed: [ Not Installed ] |
| 182 | + Size of files: 261 kB |
| 183 | + Homepage: http://www.digitemp.com/ http://www.ibutton.com/ |
| 184 | + Description: Temperature logging and reporting using Dallas Semiconductor's iButtons and 1-Wire protocol |
| 185 | + License: GPL-2 |
| 186 | +
|
| 187 | +* app-misc/git |
| 188 | + Latest version available: 4.3.20 |
| 189 | + Latest version installed: [ Not Installed ] |
| 190 | + Size of files: 416 kB |
| 191 | + Homepage: http://www.gnu.org/software/git/ |
| 192 | + Description: GNU Interactive Tools - increase speed and efficiency of most daily task |
| 193 | + License: GPL-2 |
| 194 | +
|
| 195 | +* dev-util/git |
| 196 | + Latest version available: 1.6.0.6 |
| 197 | + Latest version installed: ignore |
| 198 | + Size of files: 2,725 kB |
| 199 | + Homepage: http://git.or.cz/ |
| 200 | + Description: GIT - the stupid content tracker, the revision control system heavily used by the Linux kernel team |
| 201 | + License: GPL-2 |
| 202 | +
|
| 203 | +* dev-util/gitosis [ Masked ] |
| 204 | + Latest version available: 0.2_p20080825 |
| 205 | + Latest version installed: [ Not Installed ] |
| 206 | + Size of files: 31 kB |
| 207 | + Homepage: http://eagain.net/gitweb/?p=gitosis.git;a=summary |
| 208 | + Description: gitosis -- software for hosting git repositories |
| 209 | + License: GPL-2 |
| 210 | +EOF |
| 211 | + |
| 212 | + @status = mock("Status", :exitstatus => 0) |
| 213 | + @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) |
| 214 | + @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) |
86 | 215 | lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) |
87 | 216 | end |
88 | | - |
| 217 | + |
89 | 218 | end |
90 | 219 |
|
91 | 220 | describe Chef::Provider::Package::Portage, "install_package" do |
|
108 | 237 | :command => "emerge -g --color n --nospinner --quiet --oneshot =dev-util/git-1.0.0" |
109 | 238 | }) |
110 | 239 | @new_resource.stub!(:options).and_return("--oneshot") |
111 | | - |
| 240 | + |
112 | 241 | @provider.install_package("dev-util/git", "1.0.0") |
113 | 242 | end |
114 | 243 | end |
|
0 commit comments