chef-apply 0.3.3 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/chef-apply.gemspec +2 -1
- data/lib/chef_apply/action/base.rb +1 -0
- data/lib/chef_apply/action/converge_target.rb +11 -11
- data/lib/chef_apply/action/converge_target/ccr_failure_mapper.rb +100 -0
- data/lib/chef_apply/action/generate_local_policy.rb +1 -1
- data/lib/chef_apply/action/generate_temp_cookbook.rb +53 -53
- data/lib/chef_apply/action/generate_temp_cookbook/recipe_lookup.rb +124 -0
- data/lib/chef_apply/action/generate_temp_cookbook/temp_cookbook.rb +175 -0
- data/lib/chef_apply/action/install_chef.rb +8 -8
- data/lib/chef_apply/action/install_chef/minimum_chef_version.rb +85 -0
- data/lib/chef_apply/cli.rb +10 -9
- data/lib/chef_apply/cli/options.rb +2 -2
- data/lib/chef_apply/cli/validation.rb +2 -1
- data/lib/chef_apply/file_fetcher.rb +1 -1
- data/lib/chef_apply/log.rb +4 -6
- data/lib/chef_apply/startup.rb +7 -4
- data/lib/chef_apply/target_host.rb +10 -5
- data/lib/chef_apply/target_host/linux.rb +1 -1
- data/lib/chef_apply/target_resolver.rb +3 -1
- data/lib/chef_apply/telemeter.rb +1 -1
- data/lib/chef_apply/text/error_translation.rb +1 -1
- data/lib/chef_apply/text/text_wrapper.rb +2 -1
- data/lib/chef_apply/ui/error_printer.rb +15 -13
- data/lib/chef_apply/ui/plain_text_element.rb +1 -2
- data/lib/chef_apply/ui/plain_text_header.rb +1 -1
- data/lib/chef_apply/ui/terminal.rb +4 -4
- data/lib/chef_apply/version.rb +1 -1
- data/spec/spec_helper.rb +43 -3
- data/spec/unit/action/base_spec.rb +2 -1
- data/spec/unit/{errors → action/converge_target}/ccr_failure_mapper_spec.rb +12 -9
- data/spec/unit/action/converge_target_spec.rb +21 -22
- data/spec/unit/action/generate_local_policy_spec.rb +5 -5
- data/spec/unit/{recipe_lookup_spec.rb → action/generate_temp_cookbook/recipe_lookup_spec.rb} +10 -10
- data/spec/unit/{temp_cookbook_spec.rb → action/generate_temp_cookbook/temp_cookbook_spec.rb} +23 -24
- data/spec/unit/action/generate_temp_cookbook_spec.rb +4 -6
- data/spec/unit/{minimum_chef_version_spec.rb → action/install_chef/minimum_chef_version_spec.rb} +13 -13
- data/spec/unit/action/install_chef_spec.rb +4 -4
- data/spec/unit/cli/options_spec.rb +17 -17
- data/spec/unit/cli/validation_spec.rb +6 -3
- data/spec/unit/cli_spec.rb +12 -9
- data/spec/unit/log_spec.rb +1 -1
- data/spec/unit/startup_spec.rb +11 -12
- data/spec/unit/target_host/windows_spec.rb +1 -1
- data/spec/unit/target_host_spec.rb +3 -2
- data/spec/unit/telemeter_spec.rb +5 -5
- data/spec/unit/text/error_translation_spec.rb +11 -7
- data/spec/unit/ui/error_printer_spec.rb +6 -7
- metadata +24 -11
- data/Gemfile.lock +0 -400
- data/lib/chef_apply/errors/ccr_failure_mapper.rb +0 -93
- data/lib/chef_apply/minimum_chef_version.rb +0 -79
- data/lib/chef_apply/recipe_lookup.rb +0 -117
- data/lib/chef_apply/temp_cookbook.rb +0 -170
@@ -16,10 +16,9 @@
|
|
16
16
|
#
|
17
17
|
|
18
18
|
require "spec_helper"
|
19
|
-
require "chef_apply/action/converge_target"
|
20
19
|
require "chef_apply/target_host"
|
21
|
-
require "chef_apply/
|
22
|
-
require "chef_apply/
|
20
|
+
require "chef_apply/action/converge_target"
|
21
|
+
require "chef_apply/action/converge_target/ccr_failure_mapper"
|
23
22
|
|
24
23
|
RSpec.describe ChefApply::Action::ConvergeTarget do
|
25
24
|
let(:archive) { "archive.tgz" }
|
@@ -29,7 +28,7 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
29
28
|
let(:target_host) do
|
30
29
|
p = double("platform", family: platform_family)
|
31
30
|
double(ChefApply::TargetHost,
|
32
|
-
|
31
|
+
platform: p, base_os: base_os, ws_cache_path: cache_path)
|
33
32
|
end
|
34
33
|
let(:local_policy_path) { "/local/policy/path/archive.tgz" }
|
35
34
|
let(:opts) { { target_host: target_host, local_policy_path: local_policy_path } }
|
@@ -102,7 +101,7 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
102
101
|
exception_handlers << reporter
|
103
102
|
chef_license "accept-no-persist"
|
104
103
|
EOM
|
105
|
-
|
104
|
+
)
|
106
105
|
expect(target_host).to receive(:upload_file).with(local_tempfile.path, remote_config_path)
|
107
106
|
expect(subject.create_remote_config(remote_folder)).to eq(remote_config_path)
|
108
107
|
expect(local_tempfile.closed?).to eq(true)
|
@@ -126,7 +125,7 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
126
125
|
report_handlers << reporter
|
127
126
|
exception_handlers << reporter
|
128
127
|
EOM
|
129
|
-
|
128
|
+
)
|
130
129
|
expect(target_host).to receive(:upload_file).with(local_tempfile.path, remote_config_path)
|
131
130
|
expect(subject.create_remote_config(remote_folder)).to eq(remote_config_path)
|
132
131
|
expect(local_tempfile.closed?).to eq(true)
|
@@ -155,7 +154,7 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
155
154
|
exception_handlers << reporter
|
156
155
|
log_level :info
|
157
156
|
EOM
|
158
|
-
|
157
|
+
)
|
159
158
|
expect(target_host).to receive(:upload_file).with(local_tempfile.path, remote_config_path)
|
160
159
|
expect(subject.create_remote_config(remote_folder)).to eq(remote_config_path)
|
161
160
|
expect(local_tempfile.closed?).to eq(true)
|
@@ -188,7 +187,7 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
188
187
|
data_collector.mode :solo
|
189
188
|
data_collector.organization "Chef Workstation"
|
190
189
|
EOM
|
191
|
-
|
190
|
+
)
|
192
191
|
expect(target_host).to receive(:upload_file).with(local_tempfile.path, remote_config_path)
|
193
192
|
expect(subject.create_remote_config(remote_folder)).to eq(remote_config_path)
|
194
193
|
# ensure the tempfile is deleted locally
|
@@ -214,7 +213,7 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
214
213
|
report_handlers << reporter
|
215
214
|
exception_handlers << reporter
|
216
215
|
EOM
|
217
|
-
|
216
|
+
)
|
218
217
|
expect(target_host).to receive(:upload_file).with(local_tempfile.path, remote_config_path)
|
219
218
|
expect(subject.create_remote_config(remote_folder)).to eq(remote_config_path)
|
220
219
|
# ensure the tempfile is deleted locally
|
@@ -303,11 +302,11 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
303
302
|
# Note we're only ensuring the command looks the same as #run_chef_cmd - we verify that run_chef_cmd
|
304
303
|
# is correct in its own test elsewhere in this file
|
305
304
|
expect(target_host).to receive(:run_command).with(subject.run_chef_cmd(remote_folder,
|
306
|
-
|
307
|
-
|
305
|
+
"workstation.rb",
|
306
|
+
"archive.tgz")).and_return result
|
308
307
|
expect(target_host).to receive(:del_dir).with(remote_folder).and_return result
|
309
308
|
|
310
|
-
|
309
|
+
%i{running_chef success}.each do |n|
|
311
310
|
expect(subject).to receive(:notify).with(n)
|
312
311
|
end
|
313
312
|
subject.perform_action
|
@@ -318,10 +317,10 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
318
317
|
|
319
318
|
it "runs the converge and reports back reboot" do
|
320
319
|
expect(target_host).to receive(:run_command).with(subject.run_chef_cmd(remote_folder,
|
321
|
-
|
322
|
-
|
320
|
+
"workstation.rb",
|
321
|
+
"archive.tgz")).and_return result
|
323
322
|
expect(target_host).to receive(:del_dir).with(remote_folder).and_return result
|
324
|
-
|
323
|
+
%i{running_chef reboot}.each do |n|
|
325
324
|
expect(subject).to receive(:notify).with(n)
|
326
325
|
end
|
327
326
|
subject.perform_action
|
@@ -333,16 +332,16 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
333
332
|
let(:report_result) { '{ "exception": "thing" }' }
|
334
333
|
let(:exception_mapper) { double("mapper") }
|
335
334
|
before do
|
336
|
-
expect(ChefApply::
|
335
|
+
expect(ChefApply::Action::ConvergeTarget::CCRFailureMapper).to receive(:new)
|
337
336
|
.and_return exception_mapper
|
338
337
|
end
|
339
338
|
|
340
339
|
it "reports back failure and reads the remote report" do
|
341
340
|
expect(target_host).to receive(:run_command).with(subject.run_chef_cmd(remote_folder,
|
342
|
-
|
343
|
-
|
341
|
+
"workstation.rb",
|
342
|
+
"archive.tgz")).and_return result
|
344
343
|
expect(target_host).to receive(:del_dir).with(remote_folder).and_return result
|
345
|
-
|
344
|
+
%i{running_chef converge_error}.each do |n|
|
346
345
|
expect(subject).to receive(:notify).with(n)
|
347
346
|
end
|
348
347
|
expect(target_host).to receive(:fetch_file_contents).with(subject.chef_report_path).and_return(report_result)
|
@@ -355,10 +354,10 @@ RSpec.describe ChefApply::Action::ConvergeTarget do
|
|
355
354
|
let(:report_result) { nil }
|
356
355
|
it "reports back failure" do
|
357
356
|
expect(target_host).to receive(:run_command).with(subject.run_chef_cmd(remote_folder,
|
358
|
-
|
359
|
-
|
357
|
+
"workstation.rb",
|
358
|
+
"archive.tgz")).and_return result
|
360
359
|
expect(target_host).to receive(:del_dir).with(remote_folder).and_return result
|
361
|
-
|
360
|
+
%i{running_chef converge_error}.each do |n|
|
362
361
|
expect(subject).to receive(:notify).with(n)
|
363
362
|
end
|
364
363
|
expect(target_host).to receive(:fetch_file_contents).with(subject.chef_report_path).and_return(report_result)
|
@@ -24,9 +24,9 @@ RSpec.describe ChefApply::Action::GenerateLocalPolicy do
|
|
24
24
|
subject { ChefApply::Action::GenerateLocalPolicy.new(cookbook: cookbook) }
|
25
25
|
let(:cookbook) do
|
26
26
|
double("TempCookbook",
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
path: "/my/temp/cookbook",
|
28
|
+
export_path: "/my/temp/cookbook/export",
|
29
|
+
policyfile_lock_path: "/my/temp/cookbook/policyfile.lock")
|
30
30
|
end
|
31
31
|
|
32
32
|
let(:installer_double) do
|
@@ -35,8 +35,8 @@ RSpec.describe ChefApply::Action::GenerateLocalPolicy do
|
|
35
35
|
|
36
36
|
let(:exporter_double) do
|
37
37
|
instance_double(ChefCLI::PolicyfileServices::ExportRepo,
|
38
|
-
|
39
|
-
|
38
|
+
archive_file_location: "/path/to/export",
|
39
|
+
run: :ok)
|
40
40
|
end
|
41
41
|
|
42
42
|
before do
|
data/spec/unit/{recipe_lookup_spec.rb → action/generate_temp_cookbook/recipe_lookup_spec.rb}
RENAMED
@@ -16,15 +16,15 @@
|
|
16
16
|
#
|
17
17
|
|
18
18
|
require "spec_helper"
|
19
|
-
require "chef_apply/recipe_lookup"
|
19
|
+
require "chef_apply/action/generate_temp_cookbook/recipe_lookup"
|
20
20
|
require "chef/exceptions"
|
21
21
|
require "chef/cookbook/cookbook_version_loader"
|
22
22
|
require "chef/cookbook_version"
|
23
23
|
require "chef/cookbook_loader"
|
24
24
|
|
25
|
-
RSpec.describe ChefApply::RecipeLookup do
|
25
|
+
RSpec.describe ChefApply::Action::GenerateTempCookbook::RecipeLookup do
|
26
26
|
let(:repo_path) { "repo_path" }
|
27
|
-
subject(:rp) { ChefApply::RecipeLookup.new([repo_path]) }
|
27
|
+
subject(:rp) { ChefApply::Action::GenerateTempCookbook::RecipeLookup.new([repo_path]) }
|
28
28
|
VL = Chef::Cookbook::CookbookVersionLoader
|
29
29
|
let(:version_loader) { instance_double(VL) }
|
30
30
|
let(:cookbook_version) { instance_double(Chef::CookbookVersion, root_dir: "dir", name: "name") }
|
@@ -56,7 +56,7 @@ RSpec.describe ChefApply::RecipeLookup do
|
|
56
56
|
context "the directory is not a cookbook" do
|
57
57
|
it "raise an InvalidCookbook error" do
|
58
58
|
expect(version_loader).to receive(:load!).and_raise(Chef::Exceptions::CookbookNotFoundInRepo.new)
|
59
|
-
expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::RecipeLookup::InvalidCookbook)
|
59
|
+
expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::InvalidCookbook)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -77,17 +77,17 @@ RSpec.describe ChefApply::RecipeLookup do
|
|
77
77
|
|
78
78
|
context "and a cookbook exists but it is invalid" do
|
79
79
|
it "raises an InvalidCookbook error" do
|
80
|
-
expect(cookbook_loader).to receive(:[]).with(recipe_specifier).and_raise(Chef::Exceptions::CookbookNotFoundInRepo.new
|
80
|
+
expect(cookbook_loader).to receive(:[]).with(recipe_specifier).and_raise(Chef::Exceptions::CookbookNotFoundInRepo.new)
|
81
81
|
expect(File).to receive(:directory?).with(File.join(repo_path, recipe_specifier)).and_return(true)
|
82
|
-
expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::RecipeLookup::InvalidCookbook)
|
82
|
+
expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::InvalidCookbook)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
context "and a cookbook does not exist" do
|
87
87
|
it "raises an CookbookNotFound error" do
|
88
|
-
expect(cookbook_loader).to receive(:[]).with(recipe_specifier).and_raise(Chef::Exceptions::CookbookNotFoundInRepo.new
|
88
|
+
expect(cookbook_loader).to receive(:[]).with(recipe_specifier).and_raise(Chef::Exceptions::CookbookNotFoundInRepo.new)
|
89
89
|
expect(File).to receive(:directory?).with(File.join(repo_path, recipe_specifier)).and_return(false)
|
90
|
-
expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::RecipeLookup::CookbookNotFound)
|
90
|
+
expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::CookbookNotFound)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -103,7 +103,7 @@ RSpec.describe ChefApply::RecipeLookup do
|
|
103
103
|
end
|
104
104
|
it "when there is no default recipe it raises a NoDefaultRecipe error" do
|
105
105
|
expect(cookbook_version).to receive(:recipe_filenames_by_name).and_return({})
|
106
|
-
expect { rp.find_recipe(cookbook_version) }.to raise_error(ChefApply::RecipeLookup::NoDefaultRecipe)
|
106
|
+
expect { rp.find_recipe(cookbook_version) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::NoDefaultRecipe)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -115,7 +115,7 @@ RSpec.describe ChefApply::RecipeLookup do
|
|
115
115
|
end
|
116
116
|
it "when there is no recipe with that name it raises a RecipeNotFound error" do
|
117
117
|
expect(cookbook_version).to receive(:recipe_filenames_by_name).and_return({})
|
118
|
-
expect { rp.find_recipe(cookbook_version, desired_recipe) }.to raise_error(ChefApply::RecipeLookup::RecipeNotFound)
|
118
|
+
expect { rp.find_recipe(cookbook_version, desired_recipe) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::RecipeNotFound)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
data/spec/unit/{temp_cookbook_spec.rb → action/generate_temp_cookbook/temp_cookbook_spec.rb}
RENAMED
@@ -16,12 +16,11 @@
|
|
16
16
|
#
|
17
17
|
|
18
18
|
require "spec_helper"
|
19
|
-
require "chef_apply/temp_cookbook"
|
20
19
|
require "tempfile"
|
21
20
|
require "securerandom"
|
22
|
-
|
23
|
-
RSpec.describe ChefApply::TempCookbook do
|
24
|
-
subject(:tc) { ChefApply::TempCookbook.new }
|
21
|
+
require "chef_apply/action/generate_temp_cookbook/temp_cookbook"
|
22
|
+
RSpec.describe "ChefApply::Action::GenerateTempCookbook::TempCookbook" do
|
23
|
+
subject(:tc) { ChefApply::Action::GenerateTempCookbook::TempCookbook.new }
|
25
24
|
let(:uuid) { SecureRandom.uuid }
|
26
25
|
|
27
26
|
before do
|
@@ -31,13 +30,13 @@ RSpec.describe ChefApply::TempCookbook do
|
|
31
30
|
|
32
31
|
after do
|
33
32
|
ChefApply::Config.chef.cookbook_repo_paths = @repo_paths
|
34
|
-
|
33
|
+
subject.delete
|
35
34
|
end
|
36
35
|
|
37
36
|
describe "#from_existing_recipe" do
|
38
37
|
it "raises an error if the recipe does not have a .rb extension" do
|
39
|
-
err = ChefApply::TempCookbook::UnsupportedExtension
|
40
|
-
expect {
|
38
|
+
err = ChefApply::Action::GenerateTempCookbook::TempCookbook::UnsupportedExtension
|
39
|
+
expect { subject.from_existing_recipe("/some/file.chef") }.to raise_error(err)
|
41
40
|
end
|
42
41
|
|
43
42
|
context "when there is an existing cookbook" do
|
@@ -62,15 +61,15 @@ RSpec.describe ChefApply::TempCookbook do
|
|
62
61
|
end
|
63
62
|
|
64
63
|
it "copies the whole cookbook" do
|
65
|
-
|
66
|
-
expect(File.read(File.join(
|
67
|
-
expect(File.read(File.join(
|
64
|
+
subject.from_existing_recipe(existing_recipe.path)
|
65
|
+
expect(File.read(File.join(subject.path, "recipes/default.rb"))).to eq(uuid)
|
66
|
+
expect(File.read(File.join(subject.path, "Policyfile.rb"))).to eq <<~EXPECTED_POLICYFILE
|
68
67
|
name "foo_policy"
|
69
68
|
default_source :supermarket
|
70
69
|
run_list "foo::default"
|
71
70
|
cookbook "foo", path: "."
|
72
71
|
EXPECTED_POLICYFILE
|
73
|
-
expect(File.read(File.join(
|
72
|
+
expect(File.read(File.join(subject.path, "metadata.rb"))).to eq("name \"foo\"")
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
@@ -87,31 +86,31 @@ RSpec.describe ChefApply::TempCookbook do
|
|
87
86
|
end
|
88
87
|
|
89
88
|
it "copies the existing recipe into a new cookbook" do
|
90
|
-
|
89
|
+
subject.from_existing_recipe(existing_recipe.path)
|
91
90
|
recipe_filename = File.basename(existing_recipe.path)
|
92
91
|
recipe_name = File.basename(recipe_filename, File.extname(recipe_filename))
|
93
|
-
expect(File.read(File.join(
|
94
|
-
expect(File.read(File.join(
|
92
|
+
expect(File.read(File.join(subject.path, "recipes/", recipe_filename))).to eq(uuid)
|
93
|
+
expect(File.read(File.join(subject.path, "Policyfile.rb"))).to eq <<~EXPECTED_POLICYFILE
|
95
94
|
name "cw_recipe_policy"
|
96
95
|
default_source :supermarket
|
97
96
|
run_list "cw_recipe::#{recipe_name}"
|
98
97
|
cookbook "cw_recipe", path: "."
|
99
98
|
EXPECTED_POLICYFILE
|
100
|
-
expect(File.read(File.join(
|
99
|
+
expect(File.read(File.join(subject.path, "metadata.rb"))).to eq("name \"cw_recipe\"\n")
|
101
100
|
end
|
102
101
|
end
|
103
102
|
end
|
104
103
|
|
105
104
|
describe "#from_resource" do
|
106
105
|
it "creates a recipe containing the supplied recipe" do
|
107
|
-
|
108
|
-
expect(File.read(File.join(
|
106
|
+
subject.from_resource("directory", "/tmp/foo", [])
|
107
|
+
expect(File.read(File.join(subject.path, "recipes/default.rb"))).to eq("directory '/tmp/foo'\n")
|
109
108
|
end
|
110
109
|
end
|
111
110
|
|
112
111
|
describe "#generate_metadata" do
|
113
112
|
it "generates metadata in the temp cookbook" do
|
114
|
-
f =
|
113
|
+
f = subject.generate_metadata("foo")
|
115
114
|
expect(File.read(f)).to eq("name \"foo\"\n")
|
116
115
|
end
|
117
116
|
end
|
@@ -119,7 +118,7 @@ RSpec.describe ChefApply::TempCookbook do
|
|
119
118
|
describe "#generate_policyfile" do
|
120
119
|
context "when there is no existing policyfile" do
|
121
120
|
it "generates a policyfile in the temp cookbook" do
|
122
|
-
f =
|
121
|
+
f = subject.generate_policyfile("foo", "bar")
|
123
122
|
expect(File.read(f)).to eq <<~EXPECTED_POLICYFILE
|
124
123
|
name "foo_policy"
|
125
124
|
default_source :supermarket
|
@@ -131,7 +130,7 @@ RSpec.describe ChefApply::TempCookbook do
|
|
131
130
|
context "when there are configured cookbook_repo_paths" do
|
132
131
|
it "generates a policyfile in the temp cookbook" do
|
133
132
|
ChefApply::Config.chef.cookbook_repo_paths = %w{one two}
|
134
|
-
f =
|
133
|
+
f = subject.generate_policyfile("foo", "bar")
|
135
134
|
expect(File.read(f)).to eq <<~EXPECTED_POLICYFILE
|
136
135
|
name "foo_policy"
|
137
136
|
default_source :chef_repo, "one"
|
@@ -146,12 +145,12 @@ RSpec.describe ChefApply::TempCookbook do
|
|
146
145
|
|
147
146
|
context "when there is an existing policyfile" do
|
148
147
|
before do
|
149
|
-
File.open(File.join(
|
148
|
+
File.open(File.join(subject.path, "Policyfile.rb"), "a") do |f|
|
150
149
|
f << "this is a policyfile"
|
151
150
|
end
|
152
151
|
end
|
153
152
|
it "only overrides the existing run_list in the policyfile" do
|
154
|
-
f =
|
153
|
+
f = subject.generate_policyfile("foo", "bar")
|
155
154
|
expect(File.read(f)).to eq <<~EXPECTED_POLICYFILE
|
156
155
|
this is a policyfile
|
157
156
|
# Overriding run_list with command line specified value
|
@@ -167,7 +166,7 @@ RSpec.describe ChefApply::TempCookbook do
|
|
167
166
|
let(:props) { nil }
|
168
167
|
context "when no properties are provided" do
|
169
168
|
it "it creates a simple resource" do
|
170
|
-
expect(
|
169
|
+
expect(subject.create_resource_definition(r1, r2, [])).to eq("directory '/tmp'\n")
|
171
170
|
end
|
172
171
|
end
|
173
172
|
|
@@ -192,7 +191,7 @@ RSpec.describe ChefApply::TempCookbook do
|
|
192
191
|
key_with_underscore 'value'
|
193
192
|
end
|
194
193
|
EXPECTED_RESOURCE
|
195
|
-
expect(
|
194
|
+
expect(subject.create_resource_definition(r1, r2, props)).to eq(expected)
|
196
195
|
end
|
197
196
|
end
|
198
197
|
end
|
@@ -33,7 +33,8 @@ RSpec.describe ChefApply::Action::GenerateTempCookbook do
|
|
33
33
|
let(:resource_properties) { {} }
|
34
34
|
let(:options) do
|
35
35
|
{ resource_name: "user1", resource_type: "user",
|
36
|
-
resource_properties: resource_properties }
|
36
|
+
resource_properties: resource_properties }
|
37
|
+
end
|
37
38
|
|
38
39
|
it "returns a GenerateCookbookFromResource action" do
|
39
40
|
expect(subject.from_options(options)).to be_a ChefApply::Action::GenerateCookbookFromResource
|
@@ -52,7 +53,6 @@ RSpec.describe ChefApply::Action::GenerateTempCookbook do
|
|
52
53
|
describe "#perform_action" do
|
53
54
|
subject { ChefApply::Action::GenerateTempCookbook.new( {} ) }
|
54
55
|
it "generates a cookbook, notifies caller, and makes the cookbook available" do
|
55
|
-
|
56
56
|
expect(subject).to receive(:notify).ordered.with(:generating)
|
57
57
|
expect(subject).to receive(:generate)
|
58
58
|
expect(subject).to receive(:notify).ordered.with(:success)
|
@@ -65,11 +65,9 @@ RSpec.describe ChefApply::Action::GenerateTempCookbook do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
RSpec.describe ChefApply::Action::GenerateCookbookFromRecipe do
|
68
|
-
|
69
|
-
end
|
68
|
+
xit "#generate", "Please implement me"
|
70
69
|
end
|
71
70
|
|
72
71
|
RSpec.describe ChefApply::Action::GenerateCookbookFromResource do
|
73
|
-
|
74
|
-
end
|
72
|
+
xit "#generate", "Please implement me"
|
75
73
|
end
|
data/spec/unit/{minimum_chef_version_spec.rb → action/install_chef/minimum_chef_version_spec.rb}
RENAMED
@@ -15,15 +15,15 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
#
|
17
17
|
|
18
|
-
require "chef_apply/minimum_chef_version"
|
18
|
+
require "chef_apply/action/install_chef/minimum_chef_version"
|
19
19
|
require "chef_apply/target_host"
|
20
20
|
require "spec_helper"
|
21
21
|
|
22
|
-
RSpec.describe ChefApply::MinimumChefVersion do
|
22
|
+
RSpec.describe ChefApply::Action::InstallChef::MinimumChefVersion do
|
23
23
|
let(:base_os) { :linux }
|
24
24
|
let(:version) { 14 }
|
25
25
|
let(:target) { instance_double(ChefApply::TargetHost, base_os: base_os, installed_chef_version: version) }
|
26
|
-
subject(:klass) { ChefApply::MinimumChefVersion }
|
26
|
+
subject(:klass) { ChefApply::Action::InstallChef::MinimumChefVersion }
|
27
27
|
|
28
28
|
context "#check!" do
|
29
29
|
context "when chef is not already installed on target" do
|
@@ -41,17 +41,17 @@ RSpec.describe ChefApply::MinimumChefVersion do
|
|
41
41
|
it "raises ClientNotInstalled" do
|
42
42
|
expect do
|
43
43
|
klass.check!(target, true)
|
44
|
-
end.to raise_error(ChefApply::MinimumChefVersion::ClientNotInstalled)
|
44
|
+
end.to raise_error(ChefApply::Action::InstallChef::MinimumChefVersion::ClientNotInstalled)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
%i{windows linux}.each do |os|
|
50
50
|
context "on #{os}" do
|
51
51
|
let(:base_os) { os }
|
52
52
|
[13, 14].each do |major_version|
|
53
53
|
context "when chef is already installed at the correct minimum Chef #{major_version} version" do
|
54
|
-
let(:version) { ChefApply::MinimumChefVersion::CONSTRAINTS[os][major_version] }
|
54
|
+
let(:version) { ChefApply::Action::InstallChef::MinimumChefVersion::CONSTRAINTS[os][major_version] }
|
55
55
|
it "should return :minimum_version_met" do
|
56
56
|
actual = klass.check!(target, false)
|
57
57
|
expect(:minimum_version_met).to eq(actual)
|
@@ -63,17 +63,17 @@ RSpec.describe ChefApply::MinimumChefVersion do
|
|
63
63
|
|
64
64
|
installed_expected = {
|
65
65
|
windows: {
|
66
|
-
Gem::Version.new("12.1.1") => ChefApply::MinimumChefVersion::Client13Outdated,
|
67
|
-
Gem::Version.new("13.9.0") => ChefApply::MinimumChefVersion::Client13Outdated,
|
68
|
-
Gem::Version.new("14.3.37") => ChefApply::MinimumChefVersion::Client14Outdated,
|
66
|
+
Gem::Version.new("12.1.1") => ChefApply::Action::InstallChef::MinimumChefVersion::Client13Outdated,
|
67
|
+
Gem::Version.new("13.9.0") => ChefApply::Action::InstallChef::MinimumChefVersion::Client13Outdated,
|
68
|
+
Gem::Version.new("14.3.37") => ChefApply::Action::InstallChef::MinimumChefVersion::Client14Outdated,
|
69
69
|
},
|
70
70
|
linux: {
|
71
|
-
Gem::Version.new("12.1.1") => ChefApply::MinimumChefVersion::Client13Outdated,
|
72
|
-
Gem::Version.new("13.9.0") => ChefApply::MinimumChefVersion::Client13Outdated,
|
73
|
-
Gem::Version.new("14.1.0") => ChefApply::MinimumChefVersion::Client14Outdated,
|
71
|
+
Gem::Version.new("12.1.1") => ChefApply::Action::InstallChef::MinimumChefVersion::Client13Outdated,
|
72
|
+
Gem::Version.new("13.9.0") => ChefApply::Action::InstallChef::MinimumChefVersion::Client13Outdated,
|
73
|
+
Gem::Version.new("14.1.0") => ChefApply::Action::InstallChef::MinimumChefVersion::Client14Outdated,
|
74
74
|
},
|
75
75
|
}
|
76
|
-
|
76
|
+
%i{windows linux}.each do |os|
|
77
77
|
context "on #{os}" do
|
78
78
|
let(:base_os) { os }
|
79
79
|
installed_expected[os].each do |installed, expected|
|