~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to spec/unit/provider/package/msi_spec.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'spec_helper'
 
2
 
 
3
describe 'Puppet::Provider::Package::Msi' do
 
4
  include PuppetSpec::Files
 
5
 
 
6
  before :each do
 
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')
 
10
  end
 
11
 
 
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'
 
17
      )
 
18
      resource.provider.stubs(:execute)
 
19
      resource.provider.install
 
20
 
 
21
      File.should be_exists File.join(@state_dir, 'mysql-5.1.58-winx64.yml')
 
22
    end
 
23
 
 
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' }
 
29
      )
 
30
 
 
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
 
33
    end
 
34
 
 
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' }
 
40
      )
 
41
 
 
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
 
44
    end
 
45
 
 
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"' }
 
51
      )
 
52
 
 
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
 
55
    end
 
56
 
 
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'
 
61
      )
 
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/)
 
64
 
 
65
      File.should_not be_exists File.join(@state_dir, 'mysql-5.1.58-winx64.yml')
 
66
    end
 
67
 
 
68
    it 'should fail if the source parameter is not set' do
 
69
      expect do
 
70
        resource = Puppet::Type.type(:package).new(
 
71
          :name => 'mysql-5.1.58-winx64'
 
72
        )
 
73
      end.to raise_error(Puppet::Error, /The source parameter is required when using the MSI provider/)
 
74
    end
 
75
 
 
76
    it 'should fail if the source parameter is empty' do
 
77
      expect do
 
78
        resource = Puppet::Type.type(:package).new(
 
79
          :name   => 'mysql-5.1.58-winx64',
 
80
          :source => ''
 
81
        )
 
82
      end.to raise_error(Puppet::Error, /The source parameter cannot be empty when using the MSI provider/)
 
83
    end
 
84
  end
 
85
 
 
86
  describe 'when uninstalling' do
 
87
    before :each 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'}
 
90
    end
 
91
 
 
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'
 
96
      )
 
97
      resource.provider.stubs(:msiexec)
 
98
      resource.provider.uninstall
 
99
 
 
100
      File.should_not be_exists File.join(Puppet[:vardir], 'db', 'package', 'msi', 'mysql-5.1.58-winx64.yml')
 
101
    end
 
102
 
 
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'
 
107
      )
 
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/)
 
110
 
 
111
      File.should be_exists File.join(@state_dir, 'mysql-5.1.58-winx64.yml')
 
112
    end
 
113
 
 
114
    it 'should fail if the source parameter is not set' do
 
115
      expect do
 
116
        resource = Puppet::Type.type(:package).new(
 
117
          :name => 'mysql-5.1.58-winx64'
 
118
        )
 
119
      end.to raise_error(Puppet::Error, /The source parameter is required when using the MSI provider/)
 
120
    end
 
121
 
 
122
    it 'should fail if the source parameter is empty' do
 
123
      expect do
 
124
        resource = Puppet::Type.type(:package).new(
 
125
          :name   => 'mysql-5.1.58-winx64',
 
126
          :source => ''
 
127
        )
 
128
      end.to raise_error(Puppet::Error, /The source parameter cannot be empty when using the MSI provider/)
 
129
    end
 
130
  end
 
131
 
 
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']
 
136
 
 
137
      package_names.each do |state_file|
 
138
        File.open(File.join(@state_dir, "#{state_file}.yml"), 'w') {|f| f.puts 'Hello'}
 
139
      end
 
140
 
 
141
      installed_package_names = Puppet::Type.type(:package).provider(:msi).instances.collect {|p| p.name}
 
142
 
 
143
      installed_package_names.should =~ package_names
 
144
    end
 
145
  end
 
146
 
 
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'}
 
150
 
 
151
    resource = Puppet::Type.type(:package).new(
 
152
      :name   => 'mysql-5.1.58-winx64',
 
153
      :source => 'E:\mysql-5.1.58-winx64.msi'
 
154
    )
 
155
 
 
156
    resource.provider.query.should == {
 
157
      :name   => 'mysql-5.1.58-winx64',
 
158
      :ensure => :installed
 
159
    }
 
160
  end
 
161
 
 
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'
 
166
    )
 
167
 
 
168
    resource.provider.query.should be_nil
 
169
  end
 
170
end