Improve test coverage of swift::storage::disk

Change-Id: I746016635f36f0940c0515c4bf49fec11c43c602
This commit is contained in:
Takashi Kajinami 2022-05-22 23:57:51 +09:00
parent 12ce6b7631
commit 7f96ac35d4

View File

@ -1,26 +1,21 @@
require 'spec_helper' require 'spec_helper'
describe 'swift::storage::disk' do describe 'swift::storage::disk' do
# TODO add more unit tests
let :title do let :title do
'sdb' 'sdb'
end end
shared_examples 'swift::storage::disk' do
context 'with defaults' do
let :params do let :params do
{ {}
:base_dir => '/dev',
:mnt_base_dir => '/srv/node',
:byte_size => '1024',
:ext_args => 'mkpart primary 0% 100%',
}
end end
shared_examples 'swift::storage::disk' do it { is_expected.to contain_exec('create_partition_label-sdb').with(
it { is_expected.to contain_exec("create_partition_label-sdb").with( :command => 'parted -s /dev/sdb mklabel gpt ',
:command => "parted -s #{params[:base_dir]}/sdb mklabel gpt #{params[:ext_args]}", :path => ['/usr/bin/', '/sbin', '/bin'],
:path => ["/usr/bin/", "/sbin", "/bin"], :onlyif => ['test -b /dev/sdb', 'parted /dev/sdb print|tail -1|grep \'Error\''],
:onlyif => ["test -b #{params[:base_dir]}/sdb","parted #{params[:base_dir]}/sdb print|tail -1|grep 'Error'"],
:before => 'Anchor[swift::config::end]' :before => 'Anchor[swift::config::end]'
)} )}
@ -28,10 +23,47 @@ describe 'swift::storage::disk' do
:device => '/dev/sdb', :device => '/dev/sdb',
:mnt_base_dir => '/srv/node', :mnt_base_dir => '/srv/node',
:byte_size => '1024', :byte_size => '1024',
:loopback => false :loopback => false,
:manage_filesystem => true,
) } ) }
end end
context 'with parameters' do
let :params do
{
:mnt_base_dir => '/srv/data',
:byte_size => '2048',
:ext_args => 'mkpart primary 0% 100%',
:manage_filesystem => false,
}
end
it { is_expected.to contain_exec('create_partition_label-sdb').with(
:command => 'parted -s /dev/sdb mklabel gpt mkpart primary 0% 100%',
:path => ['/usr/bin/', '/sbin', '/bin'],
:onlyif => ['test -b /dev/sdb', 'parted /dev/sdb print|tail -1|grep \'Error\''],
:before => 'Anchor[swift::config::end]'
)}
it { is_expected.to contain_swift__storage__xfs('sdb').with(
:device => '/dev/sdb',
:mnt_base_dir => '/srv/data',
:byte_size => '2048',
:loopback => false,
:manage_filesystem => false,
) }
end
context 'with partition is not managed' do
let :params do
{
:manage_partition => false
}
end
it { is_expected.to_not contain_exec('create_partition_label-sdb') }
end
end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|