diff --git a/spec/classes/openvmtools_init_spec.rb b/spec/classes/openvmtools_init_spec.rb index d0648f3..1e3b0d3 100644 --- a/spec/classes/openvmtools_init_spec.rb +++ b/spec/classes/openvmtools_init_spec.rb @@ -2,292 +2,51 @@ require 'spec_helper' -describe 'openvmtools', type: 'class' do - context 'on a non-supported os, non-vmware platform' do - let(:params) { {} } - let :facts do - { - operatingsystem: 'foo', - operatingsystemmajrelease: '1', - operatingsystemrelease: '1', - os: { - family: 'foo', - name: 'foo', - release: { - full: '1.1', - major: '1', - minor: '1' - } - }, - osfamily: 'foo', - virtual: 'foo' - } - end - - it { is_expected.not_to contain_package('open-vm-tools') } - it { is_expected.not_to contain_package('open-vm-tools-desktop') } - it { is_expected.not_to contain_service('vgauthd') } - it { is_expected.not_to contain_service('vmtoolsd') } - end - - context 'on a supported os, non-vmware platform' do - let(:params) { {} } - let :facts do - { - operatingsystem: 'RedHat', - operatingsystemmajrelease: '7', - operatingsystemrelease: '7.0', - os: { - family: 'RedHat', - name: 'RedHat', - release: { - full: '7.0', - major: '7', - minor: '0' - } - }, - osfamily: 'RedHat', - virtual: 'foo' - } - end - - it { is_expected.not_to contain_package('open-vm-tools') } - it { is_expected.not_to contain_package('open-vm-tools-desktop') } - it { is_expected.not_to contain_service('vgauthd') } - it { is_expected.not_to contain_service('vmtoolsd') } - end - - context 'on a supported RedHat 7 os, vmware platform, default parameters' do - let(:params) { {} } - let :facts do - { - operatingsystem: 'RedHat', - operatingsystemmajrelease: '7', - operatingsystemrelease: '7.0', - os: { - family: 'RedHat', - name: 'RedHat', - release: { - full: '7.0', - major: '7', - minor: '0' - } - }, - osfamily: 'RedHat', - virtual: 'vmware' - } - end - - it { is_expected.to contain_package('open-vm-tools') } - it { is_expected.not_to contain_package('open-vm-tools-desktop') } - - it { - is_expected.to contain_service('vgauthd').with( - ensure: 'running', - enable: true, - hasstatus: true, - require: '[Package[open-vm-tools]{:name=>"open-vm-tools"}]' - ) - } - - it { - is_expected.to contain_service('vmtoolsd').with( - ensure: 'running', - enable: true, - hasstatus: true, - require: '[Package[open-vm-tools]{:name=>"open-vm-tools"}]' - ) - } - end - - context 'on a supported Ubuntu 20.04 os, vmware platform, default parameters' do - let(:params) { {} } - let :facts do - { - operatingsystem: 'Ubuntu', - operatingsystemmajrelease: '20.04', - operatingsystemrelease: '20.04', - os: { - family: 'Debian', - name: 'Ubuntu', - release: { - full: '20.04', - major: '20.04', - } - }, - osfamily: 'Debian', - virtual: 'vmware' - } - end - - it { is_expected.to contain_package('open-vm-tools') } - it { is_expected.not_to contain_package('open-vm-tools-desktop') } - - it { - is_expected.to contain_service('open-vm-tools').with( - ensure: 'running', - enable: true, - hasstatus: false, - require: '[Package[open-vm-tools]{:name=>"open-vm-tools"}]' - ) - } - end - - context 'on a supported FreeBSD 10 os, vmware platform, default parameters' do - let(:params) { {} } - let :facts do - { - operatingsystem: 'FreeBSD', - operatingsystemmajrelease: '10', - operatingsystemrelease: '10.4-RELEASE', - os: { - family: 'FreeBSD', - name: 'FreeBSD', - release: { - full: '10.4-RELEASE', - major: '10', - minor: '4' - } - }, - osfamily: 'FreeBSD', - virtual: 'vmware' - } - end - - it { is_expected.to contain_package('open-vm-tools-nox11') } - it { is_expected.not_to contain_package('open-vm-tools') } - - it { - is_expected.to contain_service('vmware_guestd').with( - ensure: 'running', - enable: true, - hasstatus: true, - require: "[Package[open-vm-tools-nox11]\ -{:name=>\"open-vm-tools-nox11\"}]" - ) - } - end - - context 'on a supported FreeBSD 11 os, vmware platform, default parameters' do - let(:params) { {} } - let :facts do - { - operatingsystem: 'FreeBSD', - operatingsystemmajrelease: '11', - operatingsystemrelease: '11.2-RELEASE', - os: { - family: 'FreeBSD', - name: 'FreeBSD', - release: { - full: '11.2-RELEASE', - major: '11', - minor: '2' - } - }, - osfamily: 'FreeBSD', - virtual: 'vmware' - } - end - - it { is_expected.to contain_package('open-vm-tools-nox11') } - it { is_expected.not_to contain_package('open-vm-tools') } - - it { - is_expected.to contain_service('vmware_guestd').with( - ensure: 'running', - enable: true, - hasstatus: true, - require: "[Package[open-vm-tools-nox11]\ -{:name=>\"open-vm-tools-nox11\"}]" - ) - } - end - - context 'on a supported RedHat 7 os, vmware platform, custom parameters' do - let :facts do - { - operatingsystem: 'RedHat', - operatingsystemmajrelease: '7', - operatingsystemrelease: '7.0', - os: { - family: 'RedHat', - name: 'RedHat', - release: { - full: '7.0', - major: '7', - minor: '0' - } - }, - osfamily: 'RedHat', - virtual: 'vmware' - } - end - - describe 'ensure => absent' do - let(:params) { { ensure: 'absent' } } - - it { is_expected.to contain_package('open-vm-tools').with_ensure('absent') } - it { is_expected.to contain_service('vgauthd').with_ensure('stopped') } - it { is_expected.to contain_service('vmtoolsd').with_ensure('stopped') } - end - - describe 'with_desktop => true' do - let(:params) { { with_desktop: true } } - - it { - is_expected.to contain_package('open-vm-tools-desktop').with_ensure('present') - } - end - - describe 'uninstall_vmware_tools => true' do - let(:params) { { uninstall_vmware_tools: true } } +describe 'openvmtools' do + on_supported_os.each do |os, os_facts| + context "os #{os}" do + let(:facts) do + os_facts.merge({ virtual: 'vmware' }) + end + let(:service_name) do + case facts[:os]['family'] + when 'Debian' + 'open-vm-tools' + when 'FreeBSD' + 'vmware_guestd' + else + 'vmtoolsd' + end + end + let(:package_name) do + case facts[:os]['family'] + when 'FreeBSD' + 'open-vm-tools-nox11' + else + 'open-vm-tools' + end + end + + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_package(package_name) } + it { is_expected.not_to contain_package('open-vm-tools-desktop') } it { - is_expected.to contain_package('VMwareTools').with_ensure('absent') - } - end - end - - context 'on a supported FreeBSD 11 os, vmware platform, custom parameters' do - let :facts do - { - operatingsystem: 'FreeBSD', - operatingsystemmajrelease: '11', - operatingsystemrelease: '11.2-RELEASE', - os: { - family: 'FreeBSD', - name: 'FreeBSD', - release: { - full: '11.2-RELEASE', - major: '11', - minor: '2' - } - }, - osfamily: 'FreeBSD', - virtual: 'vmware' + case facts[:os]['family'] + when 'RedHat' + is_expected.to contain_service('vgauthd').with( + ensure: 'running', + enable: true + ).that_requires("Package[#{package_name}]") + end } - end - - describe 'ensure => absent' do - let(:params) { { ensure: 'absent' } } - - it { is_expected.to contain_package('open-vm-tools-nox11').with_ensure('absent') } - it { is_expected.to contain_service('vmware_guestd').with_ensure('stopped') } - end - - describe 'with_desktop => true' do - let(:params) { { with_desktop: true } } - - it { is_expected.to contain_package('open-vm-tools') } - it { is_expected.not_to contain_package('open-vm-tools-nox11') } it { - is_expected.to contain_service('vmware_guestd').with( + is_expected.to contain_service(service_name).with( ensure: 'running', - enable: true, - hasstatus: true, - require: '[Package[open-vm-tools]{:name=>"open-vm-tools"}]' - ) + enable: true + ).that_requires("Package[#{package_name}]") } end end diff --git a/spec/functions/supported_spec.rb b/spec/functions/supported_spec.rb index b079aa5..da07d8d 100644 --- a/spec/functions/supported_spec.rb +++ b/spec/functions/supported_spec.rb @@ -3,37 +3,13 @@ require 'spec_helper' describe 'openvmtools::supported' do - context 'On Debian 10' do - let(:facts) do - { - os: { - name: 'Debian', - release: { - major: '10', - } - } - } - end - - it 'returns false' do - is_expected.to run.with_params('openvmtools').and_return(false) - end - end - - context 'On Debian 11' do - let(:facts) do - { - os: { - name: 'Debian', - release: { - major: '11', - } - } - } - end + on_supported_os.each do |os, os_facts| + context "On #{os}" do + let(:facts) { os_facts.merge(virtual: 'vmware') } - it 'returns true' do - is_expected.to run.with_params('openvmtools').and_return(true) + it 'returns true' do + is_expected.to run.with_params('openvmtools').and_return(true) + end end end end