chef 11.14.0.alpha.2-x86-mingw32 → 11.14.0.alpha.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/chef-service-manager +1 -1
- data/lib/chef/application.rb +8 -2
- data/lib/chef/chef_fs/command_line.rb +4 -4
- data/lib/chef/chef_fs/file_system.rb +3 -3
- data/lib/chef/chef_fs/parallelizer.rb +66 -90
- data/lib/chef/chef_fs/parallelizer/flatten_enumerable.rb +35 -0
- data/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb +279 -0
- data/lib/chef/config.rb +36 -2
- data/lib/chef/cookbook/cookbook_version_loader.rb +0 -1
- data/lib/chef/cookbook/synchronizer.rb +64 -42
- data/lib/chef/cookbook_uploader.rb +4 -25
- data/lib/chef/cookbook_version.rb +12 -11
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +18 -1
- data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -3
- data/lib/chef/knife/bootstrap.rb +23 -1
- data/lib/chef/knife/bootstrap/chef-aix.erb +58 -0
- data/lib/chef/knife/bootstrap/chef-full.erb +16 -13
- data/lib/chef/knife/core/bootstrap_context.rb +25 -1
- data/lib/chef/knife/list.rb +9 -8
- data/lib/chef/knife/serve.rb +44 -0
- data/lib/chef/knife/show.rb +2 -3
- data/lib/chef/knife/ssh.rb +1 -0
- data/lib/chef/mixin/create_path.rb +20 -4
- data/lib/chef/node.rb +19 -3
- data/lib/chef/platform/provider_mapping.rb +0 -1
- data/lib/chef/platform/query_helpers.rb +4 -3
- data/lib/chef/provider/env/windows.rb +10 -3
- data/lib/chef/provider/file.rb +1 -1
- data/lib/chef/provider/mount.rb +84 -42
- data/lib/chef/provider/package/freebsd/base.rb +92 -0
- data/lib/chef/provider/package/freebsd/pkg.rb +113 -0
- data/lib/chef/provider/package/freebsd/pkgng.rb +80 -0
- data/lib/chef/provider/package/freebsd/port.rb +70 -0
- data/lib/chef/providers.rb +3 -1
- data/lib/chef/resource/chef_gem.rb +2 -1
- data/lib/chef/resource/freebsd_package.rb +39 -3
- data/lib/chef/resource/lwrp_base.rb +2 -2
- data/lib/chef/resource/mount.rb +9 -9
- data/lib/chef/util/threaded_job_queue.rb +61 -0
- data/lib/chef/version.rb +1 -1
- data/lib/chef/version/platform.rb +2 -0
- data/lib/chef/whitelist.rb +82 -0
- data/lib/chef/win32/registry.rb +0 -1
- data/lib/chef/win32/version.rb +4 -3
- data/spec/functional/win32/versions_spec.rb +4 -4
- data/spec/integration/client/ipv6_spec.rb +1 -1
- data/spec/integration/knife/chef_fs_data_store_spec.rb +1 -1
- data/spec/integration/knife/chef_repo_path_spec.rb +4 -1
- data/spec/integration/knife/common_options_spec.rb +9 -9
- data/spec/integration/knife/cookbook_api_ipv6_spec.rb +2 -2
- data/spec/integration/knife/deps_spec.rb +3 -0
- data/spec/integration/knife/list_spec.rb +3 -0
- data/spec/integration/knife/raw_spec.rb +5 -2
- data/spec/integration/knife/redirection_spec.rb +4 -1
- data/spec/integration/knife/serve_spec.rb +57 -0
- data/spec/integration/knife/show_spec.rb +3 -0
- data/spec/support/pedant/run_pedant.rb +1 -0
- data/spec/support/platform_helpers.rb +7 -5
- data/spec/support/shared/context/config.rb +21 -0
- data/spec/support/shared/functional/file_resource.rb +52 -0
- data/spec/unit/chef_fs/parallelizer.rb +482 -0
- data/spec/unit/client_spec.rb +4 -2
- data/spec/unit/config_spec.rb +66 -12
- data/spec/unit/knife/bootstrap_spec.rb +6 -0
- data/spec/unit/knife/core/bootstrap_context_spec.rb +31 -1
- data/spec/unit/node_spec.rb +73 -3
- data/spec/unit/provider/mount_spec.rb +102 -79
- data/spec/unit/provider/package/{freebsd_spec.rb → freebsd/pkg_spec.rb} +19 -32
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +155 -0
- data/spec/unit/provider/package/freebsd/port_spec.rb +160 -0
- data/spec/unit/resource/chef_gem_spec.rb +5 -0
- data/spec/unit/resource/freebsd_package_spec.rb +63 -11
- data/spec/unit/resource/mount_spec.rb +11 -0
- data/spec/unit/role_spec.rb +5 -1
- data/spec/unit/run_lock_spec.rb +2 -0
- data/spec/unit/util/threaded_job_queue_spec.rb +51 -0
- data/spec/unit/version/platform_spec.rb +1 -1
- metadata +176 -161
- data/lib/chef/provider/package/freebsd.rb +0 -149
@@ -20,7 +20,7 @@
|
|
20
20
|
require 'spec_helper'
|
21
21
|
require 'ostruct'
|
22
22
|
|
23
|
-
describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
23
|
+
describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do
|
24
24
|
before(:each) do
|
25
25
|
@node = Chef::Node.new
|
26
26
|
@events = Chef::EventDispatch::Dispatcher.new
|
@@ -28,7 +28,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
28
28
|
@new_resource = Chef::Resource::Package.new("zsh")
|
29
29
|
@current_resource = Chef::Resource::Package.new("zsh")
|
30
30
|
|
31
|
-
@provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context)
|
31
|
+
@provider = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context)
|
32
32
|
@provider.current_resource = @current_resource
|
33
33
|
::File.stub(:exist?).with('/usr/ports/Makefile').and_return(false)
|
34
34
|
end
|
@@ -39,7 +39,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should create a current resource with the name of the new_resource" do
|
42
|
-
current_resource = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context).current_resource
|
42
|
+
current_resource = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context).current_resource
|
43
43
|
current_resource.name.should == "zsh"
|
44
44
|
end
|
45
45
|
|
@@ -66,7 +66,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
66
66
|
before do
|
67
67
|
#@new_resource = Chef::Resource::Package.new("zsh")
|
68
68
|
|
69
|
-
#@provider = Chef::Provider::Package::Freebsd.new(@node, @new_resource)
|
69
|
+
#@provider = Chef::Provider::Package::Freebsd::Pkg.new(@node, @new_resource)
|
70
70
|
|
71
71
|
#@status = double("Status", :exitstatus => 0)
|
72
72
|
#@stdin = double("STDIN", :null_object => true)
|
@@ -101,7 +101,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
101
101
|
# Not happy with the form of these tests as they are far too closely tied to the implementation and so very fragile.
|
102
102
|
it "should return the ports candidate version when given a valid port path" do
|
103
103
|
@provider.stub(:port_path).and_return("/usr/ports/shells/zsh")
|
104
|
-
make_v = OpenStruct.new(:stdout => "4.3.6\n")
|
104
|
+
make_v = OpenStruct.new(:stdout => "4.3.6\n", :exitstatus => 0)
|
105
105
|
@provider.should_receive(:shell_out!).with("make -V PORTVERSION", {:cwd=>"/usr/ports/shells/zsh", :returns=>[0, 1], :env=>nil}).and_return(make_v)
|
106
106
|
@provider.ports_candidate_version.should == "4.3.6"
|
107
107
|
end
|
@@ -109,14 +109,14 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
109
109
|
it "should figure out the package name when we have ports" do
|
110
110
|
::File.stub(:exist?).with('/usr/ports/Makefile').and_return(true)
|
111
111
|
@provider.stub(:port_path).and_return("/usr/ports/shells/zsh")
|
112
|
-
make_v = OpenStruct.new(:stdout => "zsh-4.3.6_7\n")
|
112
|
+
make_v = OpenStruct.new(:stdout => "zsh-4.3.6_7\n", :exitstatus => 0)
|
113
113
|
@provider.should_receive(:shell_out!).with("make -V PKGNAME", {:cwd=>"/usr/ports/shells/zsh", :env=>nil, :returns=>[0, 1]}).and_return(make_v)
|
114
114
|
#@provider.should_receive(:ports_makefile_variable_value).with("PKGNAME").and_return("zsh-4.3.6_7")
|
115
115
|
@provider.package_name.should == "zsh"
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
describe Chef::Provider::Package::Freebsd, "install_package" do
|
119
|
+
describe Chef::Provider::Package::Freebsd::Pkg, "install_package" do
|
120
120
|
before(:each) do
|
121
121
|
@cmd_result = OpenStruct.new(:status => true)
|
122
122
|
|
@@ -130,21 +130,14 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
130
130
|
@provider.should_receive(:shell_out!).with("pkg_add -r zsh", :env => nil).and_return(@cmd_result)
|
131
131
|
@provider.install_package("zsh", "4.3.6_7")
|
132
132
|
end
|
133
|
-
|
134
|
-
it "should run make install when installing from ports" do
|
135
|
-
@new_resource.stub(:source).and_return("ports")
|
136
|
-
@provider.should_not_receive(:shell_out!).with("make -DBATCH -f /usr/ports/shells/zsh/Makefile install", :timeout => 1200, :env=>nil)
|
137
|
-
@provider.should_receive(:shell_out!).with("make -DBATCH install", :timeout => 1200, :env=>nil, :cwd => @provider.port_path).and_return(@cmd_result)
|
138
|
-
@provider.install_package("zsh", "4.3.6_7")
|
139
|
-
end
|
140
133
|
end
|
141
134
|
|
142
|
-
describe Chef::Provider::Package::Freebsd, "port path" do
|
135
|
+
describe Chef::Provider::Package::Freebsd::Pkg, "port path" do
|
143
136
|
before do
|
144
137
|
#@node = Chef::Node.new
|
145
138
|
@new_resource = Chef::Resource::Package.new("zsh")
|
146
139
|
@new_resource.cookbook_name = "adventureclub"
|
147
|
-
@provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context)
|
140
|
+
@provider = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context)
|
148
141
|
end
|
149
142
|
|
150
143
|
it "should figure out the port path from the package_name using whereis" do
|
@@ -155,7 +148,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
155
148
|
|
156
149
|
it "should use the package_name as the port path when it starts with /" do
|
157
150
|
new_resource = Chef::Resource::Package.new("/usr/ports/www/wordpress")
|
158
|
-
provider = Chef::Provider::Package::Freebsd.new(new_resource, @run_context)
|
151
|
+
provider = Chef::Provider::Package::Freebsd::Pkg.new(new_resource, @run_context)
|
159
152
|
provider.should_not_receive(:popen4)
|
160
153
|
provider.port_path.should == "/usr/ports/www/wordpress"
|
161
154
|
end
|
@@ -165,17 +158,17 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
165
158
|
# :package_name => "www/wordpress",
|
166
159
|
# :cookbook_name => "xenoparadox")
|
167
160
|
new_resource = Chef::Resource::Package.new("www/wordpress")
|
168
|
-
provider = Chef::Provider::Package::Freebsd.new(new_resource, @run_context)
|
161
|
+
provider = Chef::Provider::Package::Freebsd::Pkg.new(new_resource, @run_context)
|
169
162
|
provider.should_not_receive(:popen4)
|
170
163
|
provider.port_path.should == "/usr/ports/www/wordpress"
|
171
164
|
end
|
172
165
|
end
|
173
166
|
|
174
|
-
describe Chef::Provider::Package::Freebsd, "ruby-iconv (package with a dash in the name)" do
|
167
|
+
describe Chef::Provider::Package::Freebsd::Pkg, "ruby-iconv (package with a dash in the name)" do
|
175
168
|
before(:each) do
|
176
169
|
@new_resource = Chef::Resource::Package.new("ruby-iconv")
|
177
170
|
@current_resource = Chef::Resource::Package.new("ruby-iconv")
|
178
|
-
@provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context)
|
171
|
+
@provider = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context)
|
179
172
|
@provider.current_resource = @current_resource
|
180
173
|
@provider.stub(:port_path).and_return("/usr/ports/converters/ruby-iconv")
|
181
174
|
@provider.stub(:package_name).and_return("ruby18-iconv")
|
@@ -188,15 +181,9 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
188
181
|
@provider.should_receive(:shell_out!).with("pkg_add -r ruby18-iconv", :env => nil).and_return(@install_result)
|
189
182
|
@provider.install_package("ruby-iconv", "1.0")
|
190
183
|
end
|
191
|
-
|
192
|
-
it "should run make install when installing from ports" do
|
193
|
-
@new_resource.stub(:source).and_return("ports")
|
194
|
-
@provider.should_receive(:shell_out!).with("make -DBATCH install", :timeout => 1200, :env=>nil, :cwd => @provider.port_path).and_return(@install_result)
|
195
|
-
@provider.install_package("ruby-iconv", "1.0")
|
196
|
-
end
|
197
184
|
end
|
198
185
|
|
199
|
-
describe Chef::Provider::Package::Freebsd, "remove_package" do
|
186
|
+
describe Chef::Provider::Package::Freebsd::Pkg, "remove_package" do
|
200
187
|
before(:each) do
|
201
188
|
@pkg_delete = OpenStruct.new(:status => true)
|
202
189
|
@new_resource.version "4.3.6_7"
|
@@ -216,11 +203,11 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
216
203
|
# version of a package is currently installed and to get the port_path.
|
217
204
|
# Example package name: bonnie++
|
218
205
|
|
219
|
-
describe Chef::Provider::Package::Freebsd, "bonnie++ (package with a plus in the name :: CHEF-4371)" do
|
206
|
+
describe Chef::Provider::Package::Freebsd::Pkg, "bonnie++ (package with a plus in the name :: CHEF-4371)" do
|
220
207
|
before(:each) do
|
221
208
|
@new_resource = Chef::Resource::Package.new("bonnie++")
|
222
209
|
@current_resource = Chef::Resource::Package.new("bonnie++")
|
223
|
-
@provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context)
|
210
|
+
@provider = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context)
|
224
211
|
@provider.current_resource = @current_resource
|
225
212
|
end
|
226
213
|
|
@@ -256,11 +243,11 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
256
243
|
# The variable LATEST_LINK is named that way because the directory that "pkg_add -r" downloads from is called "Latest" and
|
257
244
|
# contains the "latest" versions of package as symbolic links to the files in the "All" directory.
|
258
245
|
|
259
|
-
describe Chef::Provider::Package::Freebsd, "install_package latest link fixes" do
|
246
|
+
describe Chef::Provider::Package::Freebsd::Pkg, "install_package latest link fixes" do
|
260
247
|
it "should install the perl binary package with the correct name" do
|
261
248
|
@new_resource = Chef::Resource::Package.new("perl5.8")
|
262
249
|
@current_resource = Chef::Resource::Package.new("perl5.8")
|
263
|
-
@provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context)
|
250
|
+
@provider = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context)
|
264
251
|
@provider.current_resource = @current_resource
|
265
252
|
@provider.stub(:package_name).and_return("perl")
|
266
253
|
@provider.stub(:latest_link_name).and_return("perl")
|
@@ -274,7 +261,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do
|
|
274
261
|
|
275
262
|
@new_resource = Chef::Resource::Package.new("mysql50-server")
|
276
263
|
@current_resource = Chef::Resource::Package.new("mysql50-server")
|
277
|
-
@provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context)
|
264
|
+
@provider = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context)
|
278
265
|
@provider.current_resource = @current_resource
|
279
266
|
@provider.stub(:package_name).and_return("mysql-server")
|
280
267
|
@provider.stub(:latest_link_name).and_return("mysql50-server")
|
@@ -0,0 +1,155 @@
|
|
1
|
+
#
|
2
|
+
# Authors:: Richard Manyanza (liseki@nyikacraftsmen.com)
|
3
|
+
# Copyright:: Copyright (c) 2014 Richard Manyanza
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
require 'ostruct'
|
22
|
+
|
23
|
+
describe Chef::Provider::Package::Freebsd::Port do
|
24
|
+
before(:each) do
|
25
|
+
@node = Chef::Node.new
|
26
|
+
@events = Chef::EventDispatch::Dispatcher.new
|
27
|
+
@run_context = Chef::RunContext.new(@node, {}, @events)
|
28
|
+
|
29
|
+
@new_resource = Chef::Resource::Package.new("zsh")
|
30
|
+
@provider = Chef::Provider::Package::Freebsd::Pkgng.new(@new_resource, @run_context)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
describe "initialization" do
|
35
|
+
it "should create a current resource with the name of the new resource" do
|
36
|
+
@provider.current_resource.is_a?(Chef::Resource::Package).should be_true
|
37
|
+
@provider.current_resource.name.should == 'zsh'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
describe "loading current resource" do
|
43
|
+
before(:each) do
|
44
|
+
@provider.stub(:current_installed_version)
|
45
|
+
@provider.stub(:candidate_version)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should set the package name" do
|
49
|
+
@provider.load_current_resource
|
50
|
+
@provider.current_resource.package_name.should == "zsh"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set the current version" do
|
54
|
+
@provider.should_receive(:current_installed_version).and_return("5.0.2")
|
55
|
+
@provider.load_current_resource
|
56
|
+
@provider.current_resource.version.should == "5.0.2"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set the candidate version" do
|
60
|
+
@provider.should_receive(:candidate_version).and_return("5.0.5")
|
61
|
+
@provider.load_current_resource
|
62
|
+
@provider.instance_variable_get(:"@candidate_version").should == "5.0.5"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
describe "determining current installed version" do
|
68
|
+
before(:each) do
|
69
|
+
@provider.stub(:supports_pkgng?)
|
70
|
+
@pkg_info = OpenStruct.new(:stdout => "zsh-3.1.7\n")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should query pkg database" do
|
74
|
+
@provider.should_receive(:shell_out!).with('pkg info "zsh"', :env => nil, :returns => [0,70]).and_return(@pkg_info)
|
75
|
+
@provider.current_installed_version.should == "3.1.7"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
describe "determining candidate version" do
|
81
|
+
it "should query repository" do
|
82
|
+
pkg_query = OpenStruct.new(:stdout => "5.0.5\n", :exitstatus => 0)
|
83
|
+
@provider.should_receive(:shell_out!).with("pkg rquery '%v' zsh", :env => nil).and_return(pkg_query)
|
84
|
+
@provider.candidate_version.should == "5.0.5"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should query specified repository when given option" do
|
88
|
+
@provider.new_resource.options('-r LocalMirror') # This requires LocalMirror repo configuration.
|
89
|
+
pkg_query = OpenStruct.new(:stdout => "5.0.3\n", :exitstatus => 0)
|
90
|
+
@provider.should_receive(:shell_out!).with("pkg rquery -r LocalMirror '%v' zsh", :env => nil).and_return(pkg_query)
|
91
|
+
@provider.candidate_version.should == "5.0.3"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return candidate version from file when given a file" do
|
95
|
+
@provider.new_resource.source("/nas/pkg/repo/zsh-5.0.1.txz")
|
96
|
+
@provider.candidate_version.should == "5.0.1"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
describe "installing a binary package" do
|
102
|
+
before(:each) do
|
103
|
+
@install_result = OpenStruct.new(:status => true)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should handle package source from file" do
|
107
|
+
@provider.new_resource.source("/nas/pkg/repo/zsh-5.0.1.txz")
|
108
|
+
@provider.should_receive(:shell_out!).
|
109
|
+
with("pkg add /nas/pkg/repo/zsh-5.0.1.txz", :env => { 'LC_ALL' => nil }).
|
110
|
+
and_return(@install_result)
|
111
|
+
@provider.install_package("zsh", "5.0.1")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should handle package source over ftp or http" do
|
115
|
+
@provider.new_resource.source("http://repo.example.com/zsh-5.0.1.txz")
|
116
|
+
@provider.should_receive(:shell_out!).
|
117
|
+
with("pkg add http://repo.example.com/zsh-5.0.1.txz", :env => { 'LC_ALL' => nil }).
|
118
|
+
and_return(@install_result)
|
119
|
+
@provider.install_package("zsh", "5.0.1")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should handle a package name" do
|
123
|
+
@provider.should_receive(:shell_out!).
|
124
|
+
with("pkg install -y zsh", :env => { 'LC_ALL' => nil }).and_return(@install_result)
|
125
|
+
@provider.install_package("zsh", "5.0.1")
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should handle a package name with a specified repo" do
|
129
|
+
@provider.new_resource.options('-r LocalMirror') # This requires LocalMirror repo configuration.
|
130
|
+
@provider.should_receive(:shell_out!).
|
131
|
+
with("pkg install -y -r LocalMirror zsh", :env => { 'LC_ALL' => nil }).and_return(@install_result)
|
132
|
+
@provider.install_package("zsh", "5.0.1")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
describe "removing a binary package" do
|
138
|
+
before(:each) do
|
139
|
+
@install_result = OpenStruct.new(:status => true)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should call pkg delete" do
|
143
|
+
@provider.should_receive(:shell_out!).
|
144
|
+
with("pkg delete -y zsh-5.0.1", :env => nil).and_return(@install_result)
|
145
|
+
@provider.remove_package("zsh", "5.0.1")
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should not include repo option in pkg delete" do
|
149
|
+
@provider.new_resource.options('-r LocalMirror') # This requires LocalMirror repo configuration.
|
150
|
+
@provider.should_receive(:shell_out!).
|
151
|
+
with("pkg delete -y zsh-5.0.1", :env => nil).and_return(@install_result)
|
152
|
+
@provider.remove_package("zsh", "5.0.1")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#
|
2
|
+
# Authors:: Richard Manyanza (liseki@nyikacraftsmen.com)
|
3
|
+
# Copyright:: Copyright (c) 2014 Richard Manyanza
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
require 'ostruct'
|
22
|
+
|
23
|
+
describe Chef::Provider::Package::Freebsd::Port do
|
24
|
+
before(:each) do
|
25
|
+
@node = Chef::Node.new
|
26
|
+
@events = Chef::EventDispatch::Dispatcher.new
|
27
|
+
@run_context = Chef::RunContext.new(@node, {}, @events)
|
28
|
+
|
29
|
+
@new_resource = Chef::Resource::Package.new("zsh")
|
30
|
+
@provider = Chef::Provider::Package::Freebsd::Port.new(@new_resource, @run_context)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
describe "initialization" do
|
35
|
+
it "should create a current resource with the name of the new resource" do
|
36
|
+
@provider.current_resource.is_a?(Chef::Resource::Package).should be_true
|
37
|
+
@provider.current_resource.name.should == 'zsh'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
describe "loading current resource" do
|
43
|
+
before(:each) do
|
44
|
+
@provider.stub(:current_installed_version)
|
45
|
+
@provider.stub(:candidate_version)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should set the package name" do
|
49
|
+
@provider.load_current_resource
|
50
|
+
@provider.current_resource.package_name.should == "zsh"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set the current version" do
|
54
|
+
@provider.should_receive(:current_installed_version).and_return("5.0.2")
|
55
|
+
@provider.load_current_resource
|
56
|
+
@provider.current_resource.version.should == "5.0.2"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set the candidate version" do
|
60
|
+
@provider.should_receive(:candidate_version).and_return("5.0.5")
|
61
|
+
@provider.load_current_resource
|
62
|
+
@provider.instance_variable_get(:"@candidate_version").should == "5.0.5"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
describe "determining current installed version" do
|
68
|
+
before(:each) do
|
69
|
+
@provider.stub(:supports_pkgng?)
|
70
|
+
@pkg_info = OpenStruct.new(:stdout => "zsh-3.1.7\n")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should check 'pkg_info' if system uses pkg_* tools" do
|
74
|
+
@provider.should_receive(:supports_pkgng?).and_return(false)
|
75
|
+
@provider.should_receive(:shell_out!).with('pkg_info -E "zsh*"', :env => nil, :returns => [0,1]).and_return(@pkg_info)
|
76
|
+
@provider.current_installed_version.should == "3.1.7"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should check 'pkg info' if system uses pkgng" do
|
80
|
+
@provider.should_receive(:supports_pkgng?).and_return(true)
|
81
|
+
@provider.should_receive(:shell_out!).with('pkg info "zsh"', :env => nil, :returns => [0,70]).and_return(@pkg_info)
|
82
|
+
@provider.current_installed_version.should == "3.1.7"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
describe "determining candidate version" do
|
88
|
+
before(:each) do
|
89
|
+
@port_version = OpenStruct.new(:stdout => "5.0.5\n", :exitstatus => 0)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return candidate version if port exists" do
|
93
|
+
::File.stub(:exist?).with('/usr/ports/Makefile').and_return(true)
|
94
|
+
@provider.stub(:port_dir).and_return('/usr/ports/shells/zsh')
|
95
|
+
@provider.should_receive(:shell_out!).with("make -V PORTVERSION", :cwd => "/usr/ports/shells/zsh", :env => nil, :returns => [0,1]).
|
96
|
+
and_return(@port_version)
|
97
|
+
@provider.candidate_version.should == "5.0.5"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should raise exception if ports tree not found" do
|
101
|
+
::File.stub(:exist?).with('/usr/ports/Makefile').and_return(false)
|
102
|
+
expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package, "Ports collection could not be found")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
describe "determining port directory" do
|
108
|
+
it "should return name if package name is absolute path" do
|
109
|
+
@provider.new_resource.stub(:package_name).and_return("/var/ports/shells/zsh")
|
110
|
+
@provider.port_dir.should == "/var/ports/shells/zsh"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should return full ports path given package name and category" do
|
114
|
+
@provider.new_resource.stub(:package_name).and_return("shells/zsh")
|
115
|
+
@provider.port_dir.should == "/usr/ports/shells/zsh"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should query system for path given just a name" do
|
119
|
+
whereis = OpenStruct.new(:stdout => "zsh: /usr/ports/shells/zsh\n")
|
120
|
+
@provider.should_receive(:shell_out!).with("whereis -s zsh", :env => nil).and_return(whereis)
|
121
|
+
@provider.port_dir.should == "/usr/ports/shells/zsh"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should raise exception if not found" do
|
125
|
+
whereis = OpenStruct.new(:stdout => "zsh:\n")
|
126
|
+
@provider.should_receive(:shell_out!).with("whereis -s zsh", :env => nil).and_return(whereis)
|
127
|
+
expect { @provider.port_dir }.to raise_error(Chef::Exceptions::Package, "Could not find port with the name zsh")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
describe "building a binary package" do
|
133
|
+
before(:each) do
|
134
|
+
@install_result = OpenStruct.new(:status => true)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should run make install in port directory" do
|
138
|
+
@provider.stub(:port_dir).and_return("/usr/ports/shells/zsh")
|
139
|
+
@provider.should_receive(:shell_out!).
|
140
|
+
with("make -DBATCH install clean", :timeout => 1800, :cwd => "/usr/ports/shells/zsh", :env => nil).
|
141
|
+
and_return(@install_result)
|
142
|
+
@provider.install_package("zsh", "5.0.5")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
describe "removing a binary package" do
|
148
|
+
before(:each) do
|
149
|
+
@install_result = OpenStruct.new(:status => true)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should run make deinstall in port directory" do
|
153
|
+
@provider.stub(:port_dir).and_return("/usr/ports/shells/zsh")
|
154
|
+
@provider.should_receive(:shell_out!).
|
155
|
+
with("make deinstall", :timeout => 300, :cwd => "/usr/ports/shells/zsh", :env => nil).
|
156
|
+
and_return(@install_result)
|
157
|
+
@provider.remove_package("zsh", "5.0.5")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|