Skip to content

Commit d200694

Browse files
committed
Add unit test for find_kernel_patch_version
To load the Lustre resource and the functions defined on it, we are using the `nothing` action. This mechanism was already used to test for example: - get_uuid on manage_ebs.rb - dcv_supported? on dcv.rb Signed-off-by: Enrico Usai <[email protected]>
1 parent 721ef11 commit d200694

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cookbooks/aws-parallelcluster-environment/spec/unit/resources/lustre_setup_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ def self.setup(chef_run)
88
end
99
end
1010
end
11+
12+
def self.nothing(chef_run)
13+
chef_run.converge_dsl('aws-parallelcluster-environment') do
14+
# This is a way to load the resource code and unit test function defined on it
15+
lustre 'nothing' do
16+
action :nothing
17+
end
18+
end
19+
end
1120
end
1221

1322
describe 'lustre:setup' do
@@ -263,6 +272,25 @@ def self.setup(chef_run)
263272
end
264273
end
265274

275+
describe 'lustre:find_kernel_patch_version' do
276+
[%w(3.10.0-1127.8.2.el7.x86_64 1127), %w(4.18.0-477.13.1.el8_7.x86_64 477)].each do |kernel_version, expected_patch_version|
277+
context "parsing #{kernel_version}" do
278+
cached(:chef_run) do
279+
runner = runner(platform: 'centos', version: '7', step_into: ['lustre']) do |node|
280+
node.override['cluster']['kernel_release'] = kernel_version
281+
end
282+
Lustre.nothing(runner)
283+
end
284+
# Mechanism to retrieve resource and then unit test find_kernel_patch_version function
285+
cached(:resource) { chef_run.find_resource('lustre', 'nothing') }
286+
287+
it "should retrieve #{expected_patch_version} patch version" do
288+
expect(resource.find_kernel_patch_version).to eq(expected_patch_version)
289+
end
290+
end
291+
end
292+
end
293+
266294
describe 'lustre:find_centos_minor_version' do
267295
context "centos version is not 7" do
268296
cached(:chef_run) do

0 commit comments

Comments
 (0)