Skip to content

Commit ead2e20

Browse files
committed
[Test] Cover the 'aws-parallelcluster-entrypoints:finalize' recipe with spec tests.
Signed-off-by: Giacomo Marciani <[email protected]>
1 parent 10552c9 commit ead2e20

File tree

1 file changed

+48
-22
lines changed

1 file changed

+48
-22
lines changed

cookbooks/aws-parallelcluster-entrypoints/spec/unit/recipes/finalize_spec.rb

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,60 @@
1414
require 'spec_helper'
1515

1616
describe 'aws-parallelcluster-entrypoints::finalize' do
17+
before do
18+
@included_recipes = []
19+
%w(
20+
aws-parallelcluster-platform::enable_chef_error_handler
21+
aws-parallelcluster-computefleet::custom_parallelcluster_node
22+
aws-parallelcluster-platform::finalize
23+
aws-parallelcluster-slurm::finalize
24+
aws-parallelcluster-environment::finalize
25+
).each do |recipe_name|
26+
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).with(recipe_name) do
27+
@included_recipes << recipe_name
28+
end
29+
end
30+
end
31+
1732
for_all_oses do |platform, version|
1833
context "on #{platform}#{version}" do
1934
for_all_node_types do |node_type|
2035
context "when #{node_type}" do
21-
cached(:chef_run) do
22-
runner = runner(platform: platform, version: version) do |node|
23-
allow_any_instance_of(Object).to receive(:fetch_config).and_return(OpenStruct.new)
24-
allow_any_instance_of(Object).to receive(:is_custom_node?).and_return(true)
36+
[true, false].each do |is_custom_node|
37+
context "and does #{'not ' unless is_custom_node}use a custom node package" do
38+
cached(:chef_run) do
39+
runner = runner(platform: platform, version: version) do |node|
40+
allow_any_instance_of(Object).to receive(:fetch_config).and_return(OpenStruct.new)
2541

26-
node.override['cluster']['node_type'] = node_type
27-
node.override['cluster']['scheduler'] = 'slurm'
28-
end
29-
runner.converge(described_recipe)
30-
end
31-
cached(:node) { chef_run.node }
42+
node.override['cluster']['node_type'] = node_type
43+
node.override['cluster']['scheduler'] = 'slurm'
44+
node.override['cluster']['custom_node_package'] = "CUSTOM_NODE_PACKAGE" if is_custom_node
45+
end
46+
runner.converge(described_recipe)
47+
end
48+
cached(:node) { chef_run.node }
49+
50+
expected_recipes = if is_custom_node
51+
%w(
52+
aws-parallelcluster-platform::enable_chef_error_handler
53+
aws-parallelcluster-computefleet::custom_parallelcluster_node
54+
aws-parallelcluster-platform::finalize
55+
aws-parallelcluster-slurm::finalize
56+
aws-parallelcluster-environment::finalize
57+
)
58+
else
59+
%w(
60+
aws-parallelcluster-platform::enable_chef_error_handler
61+
aws-parallelcluster-platform::finalize
62+
aws-parallelcluster-slurm::finalize
63+
aws-parallelcluster-environment::finalize
64+
)
65+
end
3266

33-
%w(
34-
aws-parallelcluster-platform::enable_chef_error_handler
35-
aws-parallelcluster-computefleet::custom_parallelcluster_node
36-
aws-parallelcluster-platform::finalize aws-parallelcluster-environment::finalize
37-
aws-parallelcluster-slurm::finalize
38-
).each do |recipe_name|
39-
it "includes the recipe #{recipe_name}" do
40-
# TODO: This assertion requires to refactor all the resources having properties
41-
# aws_region and aws_domain because they are overwriting existing methods
42-
# defined in the aws-parallelcluster-shared cookbook, making the test compilation to fail.
43-
# We must re-enable this assertion once the refactoring has been done.
44-
# is_expected.to include_recipe(recipe_name)
67+
it "includes the recipes in the right order" do
68+
chef_run
69+
expect(@included_recipes).to eq(expected_recipes)
70+
end
4571
end
4672
end
4773
end

0 commit comments

Comments
 (0)