chef-dk 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +192 -0
- data/LICENSE +201 -0
- data/README.md +198 -0
- data/Rakefile +18 -0
- data/bin/chef +25 -0
- data/lib/chef-dk.rb +19 -0
- data/lib/chef-dk/builtin_commands.rb +31 -0
- data/lib/chef-dk/chef_runner.rb +83 -0
- data/lib/chef-dk/cli.rb +135 -0
- data/lib/chef-dk/command/base.rb +71 -0
- data/lib/chef-dk/command/exec.rb +33 -0
- data/lib/chef-dk/command/gem.rb +47 -0
- data/lib/chef-dk/command/generate.rb +97 -0
- data/lib/chef-dk/command/generator_commands.rb +417 -0
- data/lib/chef-dk/command/shell_init.rb +80 -0
- data/lib/chef-dk/command/verify.rb +226 -0
- data/lib/chef-dk/commands_map.rb +115 -0
- data/lib/chef-dk/component_test.rb +142 -0
- data/lib/chef-dk/cookbook_metadata.rb +36 -0
- data/lib/chef-dk/cookbook_omnifetch.rb +29 -0
- data/lib/chef-dk/cookbook_profiler/git.rb +95 -0
- data/lib/chef-dk/cookbook_profiler/identifiers.rb +79 -0
- data/lib/chef-dk/cookbook_profiler/null_scm.rb +32 -0
- data/lib/chef-dk/exceptions.rb +46 -0
- data/lib/chef-dk/generator.rb +70 -0
- data/lib/chef-dk/helpers.rb +95 -0
- data/lib/chef-dk/policyfile/chef_server_cookbook_source.rb +46 -0
- data/lib/chef-dk/policyfile/community_cookbook_source.rb +84 -0
- data/lib/chef-dk/policyfile/cookbook_sources.rb +20 -0
- data/lib/chef-dk/policyfile/cookbook_spec.rb +96 -0
- data/lib/chef-dk/policyfile/dsl.rb +148 -0
- data/lib/chef-dk/policyfile/null_cookbook_source.rb +37 -0
- data/lib/chef-dk/policyfile_compiler.rb +217 -0
- data/lib/chef-dk/policyfile_lock.rb +243 -0
- data/lib/chef-dk/shell_out.rb +36 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +3 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +96 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/converge_spec.rb +9 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/gitignore +16 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/spec_helper.rb +8 -0
- data/lib/chef-dk/skeletons/code_generator/metadata.rb +8 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/app.rb +65 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/attribute.rb +12 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +50 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook_file.rb +24 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/lwrp.rb +23 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/recipe.rb +9 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/template.rb +32 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/README.md.erb +4 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +8 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen.yml.erb +16 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +8 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/provider.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/recipe.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/resource.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/template.erb +0 -0
- data/lib/chef-dk/version.rb +20 -0
- data/spec/shared/setup_git_cookbooks.rb +53 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/test_helpers.rb +59 -0
- data/spec/unit/chef_runner_spec.rb +70 -0
- data/spec/unit/cli_spec.rb +151 -0
- data/spec/unit/command/base_spec.rb +88 -0
- data/spec/unit/command/exec_spec.rb +123 -0
- data/spec/unit/command/generate_spec.rb +102 -0
- data/spec/unit/command/generator_commands_spec.rb +504 -0
- data/spec/unit/command/shell_init_spec.rb +109 -0
- data/spec/unit/command/verify_spec.rb +311 -0
- data/spec/unit/commands_map_spec.rb +57 -0
- data/spec/unit/component_test_spec.rb +126 -0
- data/spec/unit/cookbook_metadata_spec.rb +62 -0
- data/spec/unit/cookbook_profiler/git_spec.rb +127 -0
- data/spec/unit/cookbook_profiler/identifiers_spec.rb +79 -0
- data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_one.rb +9 -0
- data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_two.rb +9 -0
- data/spec/unit/fixtures/command/cli_test_command.rb +26 -0
- data/spec/unit/fixtures/command/explicit_path_example.rb +7 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/.kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/.kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbooks_api/pruned_small_universe.json +1322 -0
- data/spec/unit/fixtures/cookbooks_api/small_universe.json +2987 -0
- data/spec/unit/fixtures/cookbooks_api/universe.json +1 -0
- data/spec/unit/fixtures/cookbooks_api/update_fixtures.rb +36 -0
- data/spec/unit/fixtures/dev_cookbooks/README.md +16 -0
- data/spec/unit/fixtures/dev_cookbooks/bar-cookbook.gitbundle +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/berkshelf/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/test-kitchen/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/integration_test +2 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/verify_me +5 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef-dk/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef/verify_me +3 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/test-kitchen/verify_me +2 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/example_app/Policyfile.rb +0 -0
- data/spec/unit/fixtures/example_cookbook/.gitignore +17 -0
- data/spec/unit/fixtures/example_cookbook/.kitchen.yml +16 -0
- data/spec/unit/fixtures/example_cookbook/Berksfile +3 -0
- data/spec/unit/fixtures/example_cookbook/README.md +4 -0
- data/spec/unit/fixtures/example_cookbook/chefignore +96 -0
- data/spec/unit/fixtures/example_cookbook/metadata.rb +8 -0
- data/spec/unit/fixtures/example_cookbook/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/.kitchen.yml +16 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +3 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/README.md +4 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/chefignore +96 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/metadata.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/metadata-missing/README.md +2 -0
- data/spec/unit/policyfile/chef_server_cookbook_source_spec.rb +34 -0
- data/spec/unit/policyfile/community_cookbook_source_spec.rb +51 -0
- data/spec/unit/policyfile/cookbook_spec_spec.rb +200 -0
- data/spec/unit/policyfile/null_cookbook_source_spec.rb +35 -0
- data/spec/unit/policyfile_builder_spec.rb +489 -0
- data/spec/unit/policyfile_demands_spec.rb +484 -0
- data/spec/unit/policyfile_evaluation_spec.rb +284 -0
- data/spec/unit/shell_out_spec.rb +34 -0
- metadata +422 -0
@@ -0,0 +1,484 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
require 'chef-dk/policyfile_compiler'
|
20
|
+
|
21
|
+
describe ChefDK::PolicyfileCompiler, "when expressing the Policyfile graph demands" do
|
22
|
+
|
23
|
+
let(:run_list) { [] }
|
24
|
+
|
25
|
+
let(:default_source) { nil }
|
26
|
+
|
27
|
+
let(:external_cookbook_universe) { {} }
|
28
|
+
|
29
|
+
let(:policyfile) do
|
30
|
+
policyfile = ChefDK::PolicyfileCompiler.new.build do |p|
|
31
|
+
|
32
|
+
p.policyfile_filename = "/no-such-place/Policyfile.rb"
|
33
|
+
|
34
|
+
p.default_source(*default_source) if default_source
|
35
|
+
p.run_list(*run_list)
|
36
|
+
|
37
|
+
allow(p.default_source).to receive(:universe_graph).and_return(external_cookbook_universe)
|
38
|
+
end
|
39
|
+
|
40
|
+
policyfile
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:demands) { policyfile.graph_demands }
|
44
|
+
|
45
|
+
shared_context("community default source") do
|
46
|
+
|
47
|
+
let(:default_source) { [:community] }
|
48
|
+
|
49
|
+
let(:external_cookbook_universe) do
|
50
|
+
{
|
51
|
+
"nginx" => {
|
52
|
+
"1.0.0" => [ [ "apt", "~> 2.0" ], [ "yum", "~> 1.0" ] ],
|
53
|
+
"1.2.0" => [ [ "apt", "~> 2.1" ], [ "yum", "~> 1.0" ] ],
|
54
|
+
"2.0.0" => [ [ "apt", "~> 3.0" ], [ "yum", "~> 1.0" ], [ "ohai", "~> 2.0" ] ]
|
55
|
+
},
|
56
|
+
|
57
|
+
"mysql" => {
|
58
|
+
"3.0.0" => [ [ "apt", "~> 2.0" ], [ "yum", "~> 1.0" ] ],
|
59
|
+
"4.0.0" => [ [ "apt", "~> 2.4" ], [ "yum", "~> 1.1" ] ],
|
60
|
+
"5.0.0" => [ ],
|
61
|
+
},
|
62
|
+
|
63
|
+
"local-cookbook" => {
|
64
|
+
"9.9.9" => [ ["local-cookbook-on-community-dep", "= 1.0.0"] ]
|
65
|
+
},
|
66
|
+
|
67
|
+
"git-sourced-cookbook" => {
|
68
|
+
"10.10.10" => [ ["git-sourced-cookbook-dep", "= 1.0.0"] ]
|
69
|
+
},
|
70
|
+
|
71
|
+
"remote-cb" => {
|
72
|
+
"0.1.0" => [ ],
|
73
|
+
"1.1.1" => [ ]
|
74
|
+
},
|
75
|
+
|
76
|
+
"local-cookbook-dep-one" => {
|
77
|
+
"1.5.0" => [ ]
|
78
|
+
},
|
79
|
+
|
80
|
+
"git-sourced-cookbook-dep" => {
|
81
|
+
"2.8.0" => [ ]
|
82
|
+
}
|
83
|
+
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
shared_context("chef server default source") do
|
89
|
+
|
90
|
+
let(:default_source) { [:chef_server, "https://chef.example.com"] }
|
91
|
+
|
92
|
+
let(:external_cookbook_universe) do
|
93
|
+
{
|
94
|
+
"nginx" => {
|
95
|
+
"1.0.0" => [ [ "apt", "~> 2.0" ], [ "yum", "~> 1.0" ] ],
|
96
|
+
},
|
97
|
+
|
98
|
+
"mysql" => {
|
99
|
+
"5.0.0" => [ ],
|
100
|
+
},
|
101
|
+
|
102
|
+
"local-cookbook" => {
|
103
|
+
"9.9.9" => [ ["local-cookbook-on-community-dep", "= 1.0.0"] ]
|
104
|
+
},
|
105
|
+
|
106
|
+
"remote-cb" => {
|
107
|
+
"1.1.1" => [ ]
|
108
|
+
},
|
109
|
+
|
110
|
+
"git-sourced-cookbook" => {
|
111
|
+
"10.10.10" => [ ["git-sourced-cookbook-dep", "= 1.0.0"] ]
|
112
|
+
},
|
113
|
+
|
114
|
+
"private-cookbook" => {
|
115
|
+
"0.1.0" => [ ]
|
116
|
+
},
|
117
|
+
|
118
|
+
"local-cookbook-dep-one" => {
|
119
|
+
"1.6.0" => [ ]
|
120
|
+
},
|
121
|
+
|
122
|
+
"git-sourced-cookbook-dep" => {
|
123
|
+
"2.9.0" => [ ]
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
before do
|
133
|
+
expect(policyfile.errors).to eq([])
|
134
|
+
end
|
135
|
+
|
136
|
+
context "Given no local or git cookbooks, no default source, and an empty run list" do
|
137
|
+
|
138
|
+
let(:run_list) { [] }
|
139
|
+
|
140
|
+
it "has an empty set of demands" do
|
141
|
+
expect(demands).to eq([])
|
142
|
+
end
|
143
|
+
|
144
|
+
it "uses an empty universe for dependencies" do
|
145
|
+
expect(policyfile.artifacts_graph).to eq({})
|
146
|
+
end
|
147
|
+
|
148
|
+
it "has an empty solution" do
|
149
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
150
|
+
expect(policyfile.graph_solution).to eq({})
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "Given a run list and no local or git cookbooks" do
|
155
|
+
|
156
|
+
let(:run_list) { ["remote-cb"] }
|
157
|
+
|
158
|
+
context "And the default source is the community site" do
|
159
|
+
|
160
|
+
include_context "community default source"
|
161
|
+
|
162
|
+
it "has an unconstrained demand on the required cookbooks" do
|
163
|
+
expect(demands).to eq([["remote-cb", ">= 0.0.0"]])
|
164
|
+
end
|
165
|
+
|
166
|
+
it "uses the community site universe for dependencies" do
|
167
|
+
expect(policyfile.artifacts_graph).to eq(external_cookbook_universe)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "uses the community cookbook in the solution" do
|
171
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
172
|
+
expect(policyfile.graph_solution).to eq({"remote-cb" => "1.1.1"})
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
context "And the default source is the chef-server" do
|
178
|
+
|
179
|
+
include_context "chef server default source"
|
180
|
+
|
181
|
+
it "has an unconstrained demand on the required cookbooks" do
|
182
|
+
expect(demands).to eq([["remote-cb", ">= 0.0.0"]])
|
183
|
+
end
|
184
|
+
|
185
|
+
it "uses the chef-server universe for dependencies" do
|
186
|
+
expect(policyfile.artifacts_graph).to eq(external_cookbook_universe)
|
187
|
+
end
|
188
|
+
|
189
|
+
it "uses the chef-server cookbook in the solution" do
|
190
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
191
|
+
expect(policyfile.graph_solution).to eq({"remote-cb" => "1.1.1"})
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "Given a local cookbook and only that cookbook in the run list" do
|
197
|
+
|
198
|
+
let(:run_list) { ['local-cookbook'] }
|
199
|
+
|
200
|
+
before do
|
201
|
+
policyfile.dsl.cookbook('local-cookbook', path: "/foo")
|
202
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:version).and_return("2.3.4")
|
203
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:dependencies).and_return([])
|
204
|
+
end
|
205
|
+
|
206
|
+
it "demands a solution using the local cookbook" do
|
207
|
+
expect(demands).to eq([["local-cookbook", "= 2.3.4"]])
|
208
|
+
end
|
209
|
+
|
210
|
+
it "includes the local cookbook in the artifact universe" do
|
211
|
+
expected_artifacts_graph = {
|
212
|
+
"local-cookbook" => { "2.3.4" => [] }
|
213
|
+
}
|
214
|
+
expect(policyfile.artifacts_graph).to eq(expected_artifacts_graph)
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
context "Given a local cookbook with a dependency and only the local cookbook in the run list" do
|
220
|
+
|
221
|
+
let(:run_list) { ['local-cookbook'] }
|
222
|
+
|
223
|
+
context "And the default source is the community site" do
|
224
|
+
|
225
|
+
include_context "community default source"
|
226
|
+
|
227
|
+
before do
|
228
|
+
policyfile.dsl.cookbook("local-cookbook", path: "foo/")
|
229
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:ensure_cached)
|
230
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:version).and_return("2.3.4")
|
231
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:dependencies).and_return([ [ "local-cookbook-dep-one", "~> 1.0"] ])
|
232
|
+
end
|
233
|
+
|
234
|
+
it "demands a solution using the local cookbook" do
|
235
|
+
expect(demands).to eq([["local-cookbook", "= 2.3.4"]])
|
236
|
+
end
|
237
|
+
|
238
|
+
it "overrides the community site universe with the local cookbook and its dependencies" do
|
239
|
+
expected_artifacts_graph = external_cookbook_universe.dup
|
240
|
+
expected_artifacts_graph["local-cookbook"] = {
|
241
|
+
"2.3.4" => [ [ "local-cookbook-dep-one", "~> 1.0" ] ]
|
242
|
+
}
|
243
|
+
expect(policyfile.artifacts_graph).to eq(expected_artifacts_graph)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "uses the local cookbook in the solution and gets dependencies remotely" do
|
247
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
248
|
+
expect(policyfile.graph_solution).to eq({"local-cookbook" => "2.3.4", "local-cookbook-dep-one" => "1.5.0"})
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
context "And the default source is the chef server" do
|
253
|
+
|
254
|
+
include_context "chef server default source"
|
255
|
+
|
256
|
+
before do
|
257
|
+
policyfile.dsl.cookbook("local-cookbook", path: "foo/")
|
258
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:ensure_cached)
|
259
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:version).and_return("2.3.4")
|
260
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:dependencies).and_return([ [ "local-cookbook-dep-one", "~> 1.0"] ])
|
261
|
+
end
|
262
|
+
|
263
|
+
it "demands a solution using the local cookbook" do
|
264
|
+
expect(demands).to eq([["local-cookbook", "= 2.3.4"]])
|
265
|
+
end
|
266
|
+
|
267
|
+
it "overrides the chef server universe with the local cookbook and its dependencies" do
|
268
|
+
# all versions of "local-cookbook" from the cookbook site universe
|
269
|
+
# should be removed so we won't run into trouble if there's a community
|
270
|
+
# cookbook with the same name and version but different deps.
|
271
|
+
expected_artifacts_graph = external_cookbook_universe.dup
|
272
|
+
expected_artifacts_graph["local-cookbook"] = {
|
273
|
+
"2.3.4" => [ [ "local-cookbook-dep-one", "~> 1.0" ] ]
|
274
|
+
}
|
275
|
+
expect(policyfile.artifacts_graph).to eq(expected_artifacts_graph)
|
276
|
+
end
|
277
|
+
|
278
|
+
it "uses the local cookbook in the solution and gets dependencies remotely" do
|
279
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
280
|
+
expect(policyfile.graph_solution).to eq({"local-cookbook" => "2.3.4", "local-cookbook-dep-one" => "1.6.0"})
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
context "Given a git-sourced cookbook with no dependencies and only the git cookbook in the run list" do
|
287
|
+
|
288
|
+
let(:run_list) { ["git-sourced-cookbook"] }
|
289
|
+
|
290
|
+
before do
|
291
|
+
policyfile.dsl.cookbook("git-sourced-cookbook", git: "git://git.example.org:user/a-cookbook.git")
|
292
|
+
policyfile.cookbook_spec_for("git-sourced-cookbook").stub(:ensure_cached)
|
293
|
+
policyfile.cookbook_spec_for("git-sourced-cookbook").stub(:version).and_return("8.6.7")
|
294
|
+
policyfile.cookbook_spec_for("git-sourced-cookbook").stub(:dependencies).and_return([ ])
|
295
|
+
end
|
296
|
+
|
297
|
+
it "demands a solution using the git sourced cookbook" do
|
298
|
+
expect(demands).to eq([["git-sourced-cookbook", "= 8.6.7"]])
|
299
|
+
end
|
300
|
+
|
301
|
+
it "includes the git-sourced cookbook in the universe graph" do
|
302
|
+
expected_artifacts_graph = {
|
303
|
+
"git-sourced-cookbook" => { "8.6.7" => [ ] }
|
304
|
+
}
|
305
|
+
expect(policyfile.artifacts_graph).to eq(expected_artifacts_graph)
|
306
|
+
end
|
307
|
+
|
308
|
+
it "uses the git sourced cookbook in the solution" do
|
309
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
310
|
+
expect(policyfile.graph_solution).to eq({"git-sourced-cookbook" => "8.6.7"})
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context "Given a git-sourced cookbook with a dependency and only the git cookbook in the run list" do
|
315
|
+
|
316
|
+
let(:run_list) { ["git-sourced-cookbook"] }
|
317
|
+
|
318
|
+
before do
|
319
|
+
policyfile.dsl.cookbook("git-sourced-cookbook", git: "git://git.example.org:user/a-cookbook.git")
|
320
|
+
policyfile.cookbook_spec_for("git-sourced-cookbook").stub(:ensure_cached)
|
321
|
+
policyfile.cookbook_spec_for("git-sourced-cookbook").stub(:version).and_return("8.6.7")
|
322
|
+
policyfile.cookbook_spec_for("git-sourced-cookbook").stub(:dependencies).and_return([ ["git-sourced-cookbook-dep", "~> 2.2" ] ])
|
323
|
+
end
|
324
|
+
|
325
|
+
context "And the default source is the community site" do
|
326
|
+
|
327
|
+
include_context "community default source"
|
328
|
+
|
329
|
+
it "demands a solution using the git sourced cookbook" do
|
330
|
+
expect(demands).to eq([["git-sourced-cookbook", "= 8.6.7"]])
|
331
|
+
end
|
332
|
+
|
333
|
+
it "overrides the community site universe with the git-sourced cookbook and deps" do
|
334
|
+
expected_artifacts_graph = external_cookbook_universe.dup
|
335
|
+
expected_artifacts_graph["git-sourced-cookbook"] = {
|
336
|
+
"8.6.7" => [ ["git-sourced-cookbook-dep", "~> 2.2" ] ]
|
337
|
+
}
|
338
|
+
expect(policyfile.artifacts_graph).to eq(expected_artifacts_graph)
|
339
|
+
end
|
340
|
+
|
341
|
+
it "uses the git sourced cookbook with remote dependencies in the solution" do
|
342
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
343
|
+
expect(policyfile.graph_solution).to eq({"git-sourced-cookbook" => "8.6.7", "git-sourced-cookbook-dep" => "2.8.0"})
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
context "And the default source is the chef server" do
|
348
|
+
|
349
|
+
include_context "chef server default source"
|
350
|
+
|
351
|
+
it "demands a solution using the git sourced cookbook" do
|
352
|
+
expect(demands).to eq([["git-sourced-cookbook", "= 8.6.7"]])
|
353
|
+
end
|
354
|
+
|
355
|
+
it "overrides the chef server universe with the git-sourced cookbook and deps" do
|
356
|
+
expected_artifacts_graph = external_cookbook_universe.dup
|
357
|
+
expected_artifacts_graph["git-sourced-cookbook"] = {
|
358
|
+
"8.6.7" => [ ["git-sourced-cookbook-dep", "~> 2.2" ] ]
|
359
|
+
}
|
360
|
+
expect(policyfile.artifacts_graph).to eq(expected_artifacts_graph)
|
361
|
+
end
|
362
|
+
|
363
|
+
it "uses the git sourced cookbook with remote dependencies in the solution" do
|
364
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
365
|
+
expect(policyfile.graph_solution).to eq({"git-sourced-cookbook" => "8.6.7", "git-sourced-cookbook-dep" => "2.9.0"})
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
context "Given a local cookbook with a run list containing the local cookbook and another cookbook" do
|
371
|
+
|
372
|
+
let(:run_list) { ['local-cookbook', 'remote-cb'] }
|
373
|
+
|
374
|
+
before do
|
375
|
+
policyfile.dsl.cookbook("local-cookbook", path: "foo/")
|
376
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:ensure_cached)
|
377
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:version).and_return("2.3.4")
|
378
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:dependencies).and_return([])
|
379
|
+
end
|
380
|
+
|
381
|
+
context "And the default source is the community site" do
|
382
|
+
|
383
|
+
include_context "community default source"
|
384
|
+
|
385
|
+
it "demands a solution with the local cookbook and any version of the other cookbook" do
|
386
|
+
expect(demands).to eq([["local-cookbook", "= 2.3.4"], ["remote-cb", ">= 0.0.0"]])
|
387
|
+
end
|
388
|
+
|
389
|
+
it "overrides the community universe with the local cookbook and deps" do
|
390
|
+
expected_artifacts_graph = external_cookbook_universe.dup
|
391
|
+
expected_artifacts_graph["local-cookbook"] = { "2.3.4" => [ ] }
|
392
|
+
expect(policyfile.artifacts_graph).to eq(expected_artifacts_graph)
|
393
|
+
end
|
394
|
+
|
395
|
+
it "uses the locally specified cookbook and remote cookbooks in the solution" do
|
396
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
397
|
+
expect(policyfile.graph_solution).to eq({"local-cookbook" => "2.3.4", "remote-cb" => "1.1.1"})
|
398
|
+
end
|
399
|
+
|
400
|
+
end
|
401
|
+
|
402
|
+
context "And the default source is the chef server" do
|
403
|
+
|
404
|
+
include_context "chef server default source"
|
405
|
+
|
406
|
+
it "demands a solution with the local cookbook and any version of the other cookbook" do
|
407
|
+
expect(demands).to eq([["local-cookbook", "= 2.3.4"], ["remote-cb", ">= 0.0.0"]])
|
408
|
+
end
|
409
|
+
|
410
|
+
it "overrides the chef-server universe with the local cookbook and deps" do
|
411
|
+
expected_artifacts_graph = external_cookbook_universe.dup
|
412
|
+
expected_artifacts_graph["local-cookbook"] = { "2.3.4" => [ ] }
|
413
|
+
expect(policyfile.artifacts_graph).to eq(expected_artifacts_graph)
|
414
|
+
end
|
415
|
+
|
416
|
+
it "uses the locally specified cookbook and remote cookbooks in the solution" do
|
417
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
418
|
+
expect(policyfile.graph_solution).to eq({"local-cookbook" => "2.3.4", "remote-cb" => "1.1.1"})
|
419
|
+
end
|
420
|
+
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
context "given a cookbook with a version constraint in the policyfile" do
|
425
|
+
|
426
|
+
include_context "community default source"
|
427
|
+
|
428
|
+
let(:run_list) { ['remote-cb'] }
|
429
|
+
|
430
|
+
before do
|
431
|
+
policyfile.dsl.cookbook("remote-cb", "~> 0.1")
|
432
|
+
end
|
433
|
+
|
434
|
+
it "demands a solution that matches the version constraint in the policyfile" do
|
435
|
+
expect(demands).to eq([["remote-cb", "~> 0.1"]])
|
436
|
+
end
|
437
|
+
|
438
|
+
it "emits a solution that satisfies the policyfile constraint" do
|
439
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
440
|
+
expect(policyfile.graph_solution).to eq({"remote-cb" => "0.1.0"})
|
441
|
+
end
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
context "given a cookbook that isn't in the run list is specified with a version constraint in the policyfile" do
|
446
|
+
|
447
|
+
include_context "community default source"
|
448
|
+
|
449
|
+
let(:run_list) { ['local-cookbook'] }
|
450
|
+
|
451
|
+
before do
|
452
|
+
policyfile.dsl.cookbook("remote-cb", "~> 0.1")
|
453
|
+
|
454
|
+
policyfile.dsl.cookbook("local-cookbook", path: "foo/")
|
455
|
+
|
456
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:ensure_cached)
|
457
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:version).and_return("2.3.4")
|
458
|
+
policyfile.cookbook_spec_for("local-cookbook").stub(:dependencies).and_return([])
|
459
|
+
end
|
460
|
+
|
461
|
+
it "demands a solution that matches the version constraint in the policyfile" do
|
462
|
+
expect(demands).to eq([["local-cookbook", "= 2.3.4"], ["remote-cb", "~> 0.1"]])
|
463
|
+
end
|
464
|
+
|
465
|
+
it "emits a solution that satisfies the policyfile constraint" do
|
466
|
+
expect(policyfile).to receive(:ensure_cache_dir_exists)
|
467
|
+
expect(policyfile.graph_solution).to eq({"local-cookbook" => "2.3.4", "remote-cb" => "0.1.0"})
|
468
|
+
end
|
469
|
+
|
470
|
+
it "builds a policyfile lock from the constraints" do
|
471
|
+
pending
|
472
|
+
expect(policyfile).to receive(:cache_path).and_return(Pathname.new("~/.nopenope/cache"))
|
473
|
+
expect(policyfile.lock).to eq(:wat)
|
474
|
+
end
|
475
|
+
|
476
|
+
end
|
477
|
+
|
478
|
+
context "Given a run_list with roles" do
|
479
|
+
it "expands the roles from the given role source" do
|
480
|
+
pending
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
end
|