Skip to content

Commit

Permalink
Merge pull request #80 from Valantin/add-rspec-puppet-facts
Browse files Browse the repository at this point in the history
Refactoring unit test
  • Loading branch information
bastelfreak authored Mar 12, 2024
2 parents ea7a026 + 699a160 commit 9459159
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 310 deletions.
319 changes: 39 additions & 280 deletions spec/classes/openvmtools_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 6 additions & 30 deletions spec/functions/supported_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9459159

Please sign in to comment.