From 7f96ac35d4d9c0f71b11a61fe5192e0b2d7536b6 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 22 May 2022 23:57:51 +0900 Subject: [PATCH] Improve test coverage of swift::storage::disk Change-Id: I746016635f36f0940c0515c4bf49fec11c43c602 --- spec/defines/swift_storage_disk_spec.rb | 76 ++++++++++++++++++------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/spec/defines/swift_storage_disk_spec.rb b/spec/defines/swift_storage_disk_spec.rb index a17e7563..d77f5294 100644 --- a/spec/defines/swift_storage_disk_spec.rb +++ b/spec/defines/swift_storage_disk_spec.rb @@ -1,35 +1,67 @@ require 'spec_helper' describe 'swift::storage::disk' do - # TODO add more unit tests let :title do 'sdb' end - let :params do - { - :base_dir => '/dev', - :mnt_base_dir => '/srv/node', - :byte_size => '1024', - :ext_args => 'mkpart primary 0% 100%', - } - end - shared_examples 'swift::storage::disk' do - it { is_expected.to contain_exec("create_partition_label-sdb").with( - :command => "parted -s #{params[:base_dir]}/sdb mklabel gpt #{params[:ext_args]}", - :path => ["/usr/bin/", "/sbin", "/bin"], - :onlyif => ["test -b #{params[:base_dir]}/sdb","parted #{params[:base_dir]}/sdb print|tail -1|grep 'Error'"], - :before => 'Anchor[swift::config::end]' - )} + context 'with defaults' do + let :params do + {} + end - it { is_expected.to contain_swift__storage__xfs('sdb').with( - :device => '/dev/sdb', - :mnt_base_dir => '/srv/node', - :byte_size => '1024', - :loopback => false - ) } + it { is_expected.to contain_exec('create_partition_label-sdb').with( + :command => 'parted -s /dev/sdb mklabel gpt ', + :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/node', + :byte_size => '1024', + :loopback => false, + :manage_filesystem => true, + ) } + 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({