3
describe 'Puppet::Provider::Package::Msi' do
4
include PuppetSpec::Files
7
Puppet::Type.type(:package).stubs(:defaultprovider).returns(Puppet::Type.type(:package).provider(:msi))
8
Puppet[:vardir] = tmpdir('msi')
9
@state_dir = File.join(Puppet[:vardir], 'db', 'package', 'msi')
12
describe 'when installing' do
13
it 'should create a state file' do
14
resource = Puppet::Type.type(:package).new(
15
:name => 'mysql-5.1.58-winx64',
16
:source => 'E:\mysql-5.1.58-winx64.msi'
18
resource.provider.stubs(:execute)
19
resource.provider.install
21
File.should be_exists File.join(@state_dir, 'mysql-5.1.58-winx64.yml')
24
it 'should use the install_options as parameter/value pairs' do
25
resource = Puppet::Type.type(:package).new(
26
:name => 'mysql-5.1.58-winx64',
27
:source => 'E:\mysql-5.1.58-winx64.msi',
28
:install_options => { 'INSTALLDIR' => 'C:\mysql-here' }
31
resource.provider.expects(:execute).with('msiexec.exe /qn /norestart /i E:\mysql-5.1.58-winx64.msi INSTALLDIR=C:\mysql-here')
32
resource.provider.install
35
it 'should only quote the value when an install_options value has a space in it' do
36
resource = Puppet::Type.type(:package).new(
37
:name => 'mysql-5.1.58-winx64',
38
:source => 'E:\mysql-5.1.58-winx64.msi',
39
:install_options => { 'INSTALLDIR' => 'C:\mysql here' }
42
resource.provider.expects(:execute).with('msiexec.exe /qn /norestart /i E:\mysql-5.1.58-winx64.msi INSTALLDIR="C:\mysql here"')
43
resource.provider.install
46
it 'should escape embedded quotes in install_options values with spaces' do
47
resource = Puppet::Type.type(:package).new(
48
:name => 'mysql-5.1.58-winx64',
49
:source => 'E:\mysql-5.1.58-winx64.msi',
50
:install_options => { 'INSTALLDIR' => 'C:\mysql "here"' }
53
resource.provider.expects(:execute).with('msiexec.exe /qn /norestart /i E:\mysql-5.1.58-winx64.msi INSTALLDIR="C:\mysql \"here\""')
54
resource.provider.install
57
it 'should not create a state file, if the installation fails' do
58
resource = Puppet::Type.type(:package).new(
59
:name => 'mysql-5.1.58-winx64',
60
:source => 'E:\mysql-5.1.58-winx64.msi'
62
resource.provider.stubs(:execute).raises(Puppet::ExecutionFailure.new("Execution of 'msiexec.exe' returned 128: Blargle"))
63
expect { resource.provider.install }.to raise_error(Puppet::ExecutionFailure, /msiexec\.exe/)
65
File.should_not be_exists File.join(@state_dir, 'mysql-5.1.58-winx64.yml')
68
it 'should fail if the source parameter is not set' do
70
resource = Puppet::Type.type(:package).new(
71
:name => 'mysql-5.1.58-winx64'
73
end.to raise_error(Puppet::Error, /The source parameter is required when using the MSI provider/)
76
it 'should fail if the source parameter is empty' do
78
resource = Puppet::Type.type(:package).new(
79
:name => 'mysql-5.1.58-winx64',
82
end.to raise_error(Puppet::Error, /The source parameter cannot be empty when using the MSI provider/)
86
describe 'when uninstalling' do
88
FileUtils.mkdir_p(@state_dir)
89
File.open(File.join(@state_dir, 'mysql-5.1.58-winx64.yml'), 'w') {|f| f.puts 'Hello'}
92
it 'should remove the state file' do
93
resource = Puppet::Type.type(:package).new(
94
:name => 'mysql-5.1.58-winx64',
95
:source => 'E:\mysql-5.1.58-winx64.msi'
97
resource.provider.stubs(:msiexec)
98
resource.provider.uninstall
100
File.should_not be_exists File.join(Puppet[:vardir], 'db', 'package', 'msi', 'mysql-5.1.58-winx64.yml')
103
it 'should leave the state file if uninstalling fails' do
104
resource = Puppet::Type.type(:package).new(
105
:name => 'mysql-5.1.58-winx64',
106
:source => 'E:\mysql-5.1.58-winx64.msi'
108
resource.provider.stubs(:msiexec).raises(Puppet::ExecutionFailure.new("Execution of 'msiexec.exe' returned 128: Blargle"))
109
expect { resource.provider.uninstall }.to raise_error(Puppet::ExecutionFailure, /msiexec\.exe/)
111
File.should be_exists File.join(@state_dir, 'mysql-5.1.58-winx64.yml')
114
it 'should fail if the source parameter is not set' do
116
resource = Puppet::Type.type(:package).new(
117
:name => 'mysql-5.1.58-winx64'
119
end.to raise_error(Puppet::Error, /The source parameter is required when using the MSI provider/)
122
it 'should fail if the source parameter is empty' do
124
resource = Puppet::Type.type(:package).new(
125
:name => 'mysql-5.1.58-winx64',
128
end.to raise_error(Puppet::Error, /The source parameter cannot be empty when using the MSI provider/)
132
describe 'when enumerating instances' do
133
it 'should consider the base of the state file name to be the name of the package' do
134
FileUtils.mkdir_p(@state_dir)
135
package_names = ['GoogleChromeStandaloneEnterprise', 'mysql-5.1.58-winx64', 'postgresql-8.3']
137
package_names.each do |state_file|
138
File.open(File.join(@state_dir, "#{state_file}.yml"), 'w') {|f| f.puts 'Hello'}
141
installed_package_names = Puppet::Type.type(:package).provider(:msi).instances.collect {|p| p.name}
143
installed_package_names.should =~ package_names
147
it 'should consider the package installed if the state file is present' do
148
FileUtils.mkdir_p(@state_dir)
149
File.open(File.join(@state_dir, 'mysql-5.1.58-winx64.yml'), 'w') {|f| f.puts 'Hello'}
151
resource = Puppet::Type.type(:package).new(
152
:name => 'mysql-5.1.58-winx64',
153
:source => 'E:\mysql-5.1.58-winx64.msi'
156
resource.provider.query.should == {
157
:name => 'mysql-5.1.58-winx64',
158
:ensure => :installed
162
it 'should consider the package absent if the state file is missing' do
163
resource = Puppet::Type.type(:package).new(
164
:name => 'mysql-5.1.58-winx64',
165
:source => 'E:\mysql-5.1.58-winx64.msi'
168
resource.provider.query.should be_nil