Skip to content

Commit

Permalink
Adjust tests to match updates
Browse files Browse the repository at this point in the history
This is not a comprehensive test overhaul, but does update the
functional tests to work with the updated code.
  • Loading branch information
reidmv committed Nov 7, 2015
1 parent 473a961 commit e8a8cc9
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 349 deletions.
3 changes: 1 addition & 2 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ fixtures:
repositories:
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib
powershell: https://github.com/puppetlabs/puppetlabs-powershell
win_facts: https://github.com/liamjbennett/puppet-win_facts
download_file: https://github.com/opentable/puppet-download_file
remote_file: https://github.com/lwf/puppet-remote_file
symlinks:
dotnet: "#{source_dir}"
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# }
#
define dotnet(
Enum['3.5', '4.0', '4.5.1', '4.5.2']
Enum['3.5', '4.0', '4.5', '4.5.1', '4.5.2']
$version,

Enum['present', 'absent']
Expand Down
30 changes: 20 additions & 10 deletions spec/defines/dotnet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

describe 'dotnet', :type => :define do

['Windows Server 2012','Windows Server 2008 R2','Windows Server 2008', 'Windows Server 2003','Windows Server 2003 R2','Windows 8','Windows 7','Windows Vista','Windows XP'].each do |os|
context "with invalid custom param: os => #{os}, version => fubar" do
let :facts do
{ :operatingsystemversion => os }
end
['2012','2008 R2','2008', '2003','2003 R2','8','7','Vista','XP'].each do |release|
context "with invalid custom param: os.release.full => #{release}, version => fubar" do
let :title do 'fubar' end
let :params do
{ :version => 'fubar' }
end

it do
expect {
should contain_exec('install-dotnet-3.5')
}.to raise_error(Puppet::Error)
let :facts do
{ :os => {'family' => 'windows', 'release' => { 'full' => release } } }
end

it { expect { is_expected.to compile }.to raise_error(/Expected parameter .* to have type/) }
end
end

Expand All @@ -37,4 +33,18 @@
end
end
end

['unknown'].each do |release|
context "with ensure => present, version => 4.5, os.release.full => #{release}" do
let :title do 'fubar' end
let :params do
{ :version => '4.5.1', :ensure => 'present' }
end
let :facts do
{ :os => {'family' => 'windows', 'release' => { 'full' => release } } }
end

it { expect { is_expected.to compile }.to raise_error(/is not supported on windows #{release}/) }
end
end
end
130 changes: 37 additions & 93 deletions spec/defines/four_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,118 +10,62 @@
@four_reg = '{8E34682C-8118-31F1-BC4C-98CD9675E1C2}'
}

['Windows Server 2008', 'Windows Server 2008 R2', 'Windows Server 2012','Windows XP','Windows Vista','Windows 7','Windows 8'].each do |os|
context "with ensure => present, version => 4.0, os => #{os}, network package" do
let :title do 'dotnet4' end
let :params do
{ :ensure => 'present', :version => '4.0', :package_dir => "C:\\Windows\\Temp" }
end
let :facts do
{ :operatingsystemversion => os }
end

it { should contain_exec('install-dotnet-4.0').with(
'provider' => 'powershell',
'logoutput' => 'true',
'command' => "& C:\\Windows\\Temp\\#{@four_prog} /q /norestart",
'unless' => "if ((Get-Item -LiteralPath '#{@hklm}\\#{@four_reg}' -ErrorAction SilentlyContinue).GetValue('DisplayVersion')) { exit 0 }"
)}

end
let :title do 'dotnet4' end
let :params do
{ :ensure => 'present', :version => '4.0' }
end

['Windows Server 2008', 'Windows Server 2008 R2', 'Windows Server 2012','Windows XP','Windows Vista','Windows 7','Windows 8'].each do |os|
context "with ensure => present, version => 4.0, os => #{os}, download package" do
let :title do 'dotnet4' end
let :params do
{ :ensure => 'present', :version => '4.0' }
end
['2008', '2008 R2', '2012', '2012 R2', 'XP', 'Vista', '7', '8', '8.1'].each do |release|
context "with ensure => present, version => 4.0, os.release.full => #{release}" do
let :facts do
{ :operatingsystemversion => os }
{ :os => {'family' => 'windows', 'release' => { 'full' => release } } }
end

it { should contain_download_file('download-dotnet-4.0').with(
'url' => @four_url,
'destination_directory' => 'C:\\Windows\\Temp'
) }

it { should contain_exec('install-dotnet-4.0').with(
'provider' => 'powershell',
'logoutput' => 'true',
'command' => "& C:\\Windows\\Temp\\#{@four_prog} /q /norestart",
'unless' => "if ((Get-Item -LiteralPath '#{@hklm}\\#{@four_reg}' -ErrorAction SilentlyContinue).GetValue('DisplayVersion')) { exit 0 }"
)}

end
end

['unknown'].each do |os|
context "with ensure => present, version => 4.0, os => #{os}" do
let :title do 'dotnet4' end
let :params do
{ :ensure => 'present', :version => '4.0', :package_dir => "C:\\Windows\\Temp" }
end
let :facts do
{ :operatingsystemversion => os }
context "package" do
if ['2012', '2012 R2', '8', '8.1'].include? release
it { should_not contain_package('Microsoft .NET Framework 4 Extended') }
else
it { should contain_package('Microsoft .NET Framework 4 Extended').with(
'ensure' => 'present',
)}
end
end

it { should_not contain_exec('install-dotnet-4.0') }
end
end

['Windows Server 2008', 'Windows Server 2008 R2', 'Windows Server 2012','Windows XP','Windows Vista','Windows 7','Windows 8'].each do |os|
context "with ensure => absent, version => 4.0, os => #{os}" do
let :title do 'dotnet4' end
let :params do
{ :ensure => 'absent', :version => '4.0', :package_dir => "C:\\Windows\\Temp" }
context "download" do
if ['2012', '2012 R2', '8', '8.1'].include? release
it { should_not contain_remote_file('C:/Windows/Temp/dotNetFx40_Full_x86_x64.exe') }
else
it { should contain_remote_file('C:/Windows/Temp/dotNetFx40_Full_x86_x64.exe') }
end
end
let :facts do
{ :operatingsystemversion => os }
end

it { should contain_exec('uninstall-dotnet-4.0').with(
'provider' => 'powershell',
'logoutput' => 'true',
'command' => "& C:\\Windows\\Temp\\#{@four_prog} /x /q /norestart",
'unless' => "if ((Get-Item -LiteralPath '#{@hklm}\\#{@four_reg}' -ErrorAction SilentlyContinue).GetValue('DisplayVersion')) { exit 1 }"
)}
end
end

['Windows Server 2008', 'Windows Server 2008 R2', 'Windows Server 2012','Windows XP','Windows Vista','Windows 7','Windows 8'].each do |os|
context "with ensure => absent, version => 4.0, os => #{os}, download package" do
let :title do 'dotnet4' end
['2008', '2008 R2', '2012', '2012 R2', 'XP', 'Vista', '7', '8', '8.1'].each do |release|
context "with ensure => absent, version => 4.0, os.release.full => #{release}" do
let :params do
{ :ensure => 'absent', :version => '4.0' }
end
let :facts do
{ :operatingsystemversion => os }
{ :os => {'family' => 'windows', 'release' => { 'full' => release } } }
end

it { should contain_file("C:/Windows/Temp/#{@four_prog}").with(
'ensure' => 'absent'
)}

it { should contain_exec('uninstall-dotnet-4.0').with(
'provider' => 'powershell',
'logoutput' => 'true',
'command' => "& C:\\Windows\\Temp\\#{@four_prog} /x /q /norestart",
'unless' => "if ((Get-Item -LiteralPath '#{@hklm}\\#{@four_reg}' -ErrorAction SilentlyContinue).GetValue('DisplayVersion')) { exit 1 }"
)}
end
end

['unknown'].each do |os|
context "with ensure => absent, version => 4.0, os => #{os}" do
let :title do 'dotnet4' end
let :params do
{ :ensure => 'absent', :version => '4.0', :package_dir => "C:\\Windows\\Temp" }
end
let :facts do
{ :operatingsystemversion => os }
context "package" do
if not ['2012', '2012 R2', '8', '8.1'].include? release
it { should contain_package('Microsoft .NET Framework 4 Extended').with(
'ensure' => 'absent',
)}
end
end

it { should_not contain_exec('uninstall-dotnet-4.0') }
context "download" do
if not ['2012', '2012 R2', '8', '8.1'].include? release
it { should contain_remote_file('C:/Windows/Temp/dotNetFx40_Full_x86_x64.exe').with(
'ensure' => 'absent',
)}
end
end
end
end

end
135 changes: 36 additions & 99 deletions spec/defines/fourfive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,61 @@

describe 'dotnet', :type => :define do

before {
@hklm = 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall'

@four_five_url = 'http://download.microsoft.com/download/b/a/4/ba4a7e71-2906-4b2d-a0e1-80cf16844f5f/dotnetfx45_full_x86_x64.exe'
@four_five_prog = 'dotnetfx45_full_x86_x64.exe'
@four_five_reg = '{1AD147D0-BE0E-3D6C-AC11-64F6DC4163F1}'
}

['Windows Server 2008', 'Windows Server 2008 R2', 'Windows Server 2012','Windows Vista','Windows 7','Windows 8'].each do |os|
context "with ensure => present, version => 4.5, os => #{os}, network package" do
let :title do 'dotnet45' end
let :params do
{ :ensure => 'present', :version => '4.5', :package_dir => "C:\\Windows\\Temp" }
end
let :facts do
{ :operatingsystemversion => os }
end

it { should contain_exec('install-dotnet-4.5').with(
'provider' => 'powershell',
'logoutput' => 'true',
'command' => "& C:\\Windows\\Temp\\#{@four_five_prog} /q /norestart",
'unless' => "if ((Get-Item -LiteralPath '#{@hklm}\\#{@four_five_reg}' -ErrorAction SilentlyContinue).GetValue('DisplayVersion')) { exit 0 }"
)}
end
let :title do 'dotnet4' end
let :params do
{ :ensure => 'present', :version => '4.5' }
end

['Windows Server 2008', 'Windows Server 2008 R2', 'Windows Server 2012','Windows Vista','Windows 7','Windows 8'].each do |os|
context "with ensure => present, version => 4.5, os => #{os}, download package" do
let :title do 'dotnet45' end
let :params do
{ :ensure => 'present', :version => '4.5' }
end
['2008', '2008 R2', '2012', '2012 R2', 'XP', 'Vista', '7', '8', '8.1'].each do |release|
context "with ensure => present, version => 4.5, os.release.full => #{release}" do
let :facts do
{ :operatingsystemversion => os }
{ :os => {'family' => 'windows', 'release' => { 'full' => release } } }
end

it { should contain_download_file('download-dotnet-4.5').with(
'url' => @four_five_url,
'destination_directory' => 'C:\\Windows\\Temp'
) }

it { should contain_exec('install-dotnet-4.5').with(
'provider' => 'powershell',
'logoutput' => 'true',
'command' => "& C:\\Windows\\Temp\\#{@four_five_prog} /q /norestart",
'unless' => "if ((Get-Item -LiteralPath '#{@hklm}\\#{@four_five_reg}' -ErrorAction SilentlyContinue).GetValue('DisplayVersion')) { exit 0 }"
)}
end
end

['unknown','Windows Server 2003','Windows Server 2003 R2'].each do |os|
context "with ensure => present, version => 4.5, os => #{os}" do
let :title do 'dotnet45' end
let :params do
{ :ensure => 'present', :version => '4.5', :package_dir => "C:\\Windows\\Temp" }
end
let :facts do
{ :operatingsystemversion => os }
context "package" do
if ['2012', '2012 R2', '8', '8.1'].include? release
it { should_not contain_package('Microsoft .NET Framework 4.5') }
else
it { should contain_package('Microsoft .NET Framework 4.5').with(
'ensure' => 'present',
)}
end
end

it { should_not contain_exec('install-dotnet-4.5') }
end
end

['Windows Server 2008', 'Windows Server 2008 R2', 'Windows Server 2012','Windows Vista','Windows 7','Windows 8'].each do |os|
context 'with ensure => absent, version => 4.5' do
let :title do 'dotnet45' end
let :params do
{ :ensure => 'absent', :version => '4.5', :package_dir => "C:\\Windows\\Temp" }
context "download" do
if ['2012', '2012 R2', '8', '8.1'].include? release
it { should_not contain_remote_file('C:/Windows/Temp/dotnetfx45_full_x86_x64.exe') }
else
it { should contain_remote_file('C:/Windows/Temp/dotnetfx45_full_x86_x64.exe') }
end
end
let :facts do
{ :operatingsystemversion => os }
end

it { should contain_exec('uninstall-dotnet-4.5').with(
'provider' => 'powershell',
'logoutput' => 'true',
'command' => "& C:\\Windows\\Temp\\#{@four_five_prog} /x /q /norestart",
'unless' => "if ((Get-Item -LiteralPath '#{@hklm}\\#{@four_five_reg}' -ErrorAction SilentlyContinue).GetValue('DisplayVersion')) { exit 1 }"
)}
end
end

['Windows Server 2008', 'Windows Server 2008 R2', 'Windows Server 2012','Windows Vista','Windows 7','Windows 8'].each do |os|
context 'with ensure => absent, version => 4.5, download package' do
let :title do 'dotnet45' end
['2008', '2008 R2', '2012', '2012 R2', 'XP', 'Vista', '7', '8', '8.1'].each do |release|
context "with ensure => absent, version => 4.5, os.release.full => #{release}" do
let :params do
{ :ensure => 'absent', :version => '4.5' }
end
let :facts do
{ :operatingsystemversion => os }
{ :os => {'family' => 'windows', 'release' => { 'full' => release } } }
end

it { should contain_file("C:/Windows/Temp/#{@four_five_prog}").with(
'ensure' => 'absent'
)}

it { should contain_exec('uninstall-dotnet-4.5').with(
'provider' => 'powershell',
'logoutput' => 'true',
'command' => "& C:\\Windows\\Temp\\#{@four_five_prog} /x /q /norestart",
'unless' => "if ((Get-Item -LiteralPath '#{@hklm}\\#{@four_five_reg}' -ErrorAction SilentlyContinue).GetValue('DisplayVersion')) { exit 1 }"
)}
end
end

['unknown','Windows Server 2003','Windows Server 2003 R2'].each do |os|
context "with ensure => absent, version => 4.5, os => #{os}" do
let :title do 'dotnet45' end
let :params do
{ :ensure => 'absent', :version => '4.5', :package_dir => "C:\\Windows\\Temp" }
end
let :facts do
{ :operatingsystemversion => os }
context "package" do
if not ['2012', '2012 R2', '8', '8.1'].include? release
it { should contain_package('Microsoft .NET Framework 4.5').with(
'ensure' => 'absent',
)}
end
end

it { should_not contain_exec('uninstall-dotnet-4.5') }
context "download" do
if not ['2012', '2012 R2', '8', '8.1'].include? release
it { should contain_remote_file('C:/Windows/Temp/dotnetfx45_full_x86_x64.exe').with(
'ensure' => 'absent',
)}
end
end
end
end

Expand Down
Loading

0 comments on commit e8a8cc9

Please sign in to comment.