~ubuntu-branches/ubuntu/quantal/puppet/quantal

« back to all changes in this revision

Viewing changes to spec/unit/module_tool/applications/uninstaller_spec.rb

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-07-14 01:56:30 UTC
  • mfrom: (1.1.29) (3.1.43 sid)
  • Revision ID: package-import@ubuntu.com-20120714015630-ntj41rkvkq4zph4y
Tags: 2.7.18-1ubuntu1
* Resynchronise with Debian. (LP: #1023931) Remaining changes:
  - debian/puppetmaster-passenger.postinst: Make sure we error if puppet
    config print doesn't work
  - debian/puppetmaster-passenger.postinst: Ensure upgrades from
    <= 2.7.11-1 fixup passenger apache configuration.
* Dropped upstreamed patches:
  - debian/patches/CVE-2012-1906_CVE-2012-1986_to_CVE-2012-1989.patch
  - debian/patches/puppet-12844
  - debian/patches/2.7.17-Puppet-July-2012-CVE-fixes.patch
* Drop Build-Depends on ruby-rspec (in universe):
  - debian/control: remove ruby-rspec from Build-Depends
  - debian/patches/no-rspec.patch: make Rakefile work anyway if rspec
    isn't installed so we can use it in debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'spec_helper'
 
2
require 'puppet/module_tool'
 
3
require 'tmpdir'
 
4
require 'puppet_spec/modules'
 
5
 
 
6
describe Puppet::ModuleTool::Applications::Uninstaller, :fails_on_windows => true do
 
7
  include PuppetSpec::Files
 
8
 
 
9
  def mkmod(name, path, metadata=nil)
 
10
    modpath = File.join(path, name)
 
11
    FileUtils.mkdir_p(modpath)
 
12
 
 
13
    if metadata
 
14
      File.open(File.join(modpath, 'metadata.json'), 'w') do |f|
 
15
        f.write(metadata.to_pson)
 
16
      end
 
17
    end
 
18
 
 
19
    modpath
 
20
  end
 
21
 
 
22
  describe "the behavior of the instances" do
 
23
 
 
24
    before do
 
25
      @uninstaller = Puppet::ModuleTool::Applications::Uninstaller
 
26
      FileUtils.mkdir_p(modpath1)
 
27
      FileUtils.mkdir_p(modpath2)
 
28
      fake_env.modulepath = [modpath1, modpath2]
 
29
    end
 
30
 
 
31
    let(:modpath1) { File.join(tmpdir("uninstaller"), "modpath1") }
 
32
    let(:modpath2) { File.join(tmpdir("uninstaller"), "modpath2") }
 
33
    let(:fake_env) { Puppet::Node::Environment.new('fake_env') }
 
34
    let(:options)  { {:environment => "fake_env"} }
 
35
 
 
36
    let(:foo_metadata) do
 
37
      {
 
38
        :author       => "puppetlabs",
 
39
        :name         => "puppetlabs/foo",
 
40
        :version      => "1.0.0",
 
41
        :source       => "http://dummyurl/foo",
 
42
        :license      => "Apache2",
 
43
        :dependencies => [],
 
44
      }
 
45
    end
 
46
 
 
47
    let(:bar_metadata) do
 
48
      {
 
49
        :author       => "puppetlabs",
 
50
        :name         => "puppetlabs/bar",
 
51
        :version      => "1.0.0",
 
52
        :source       => "http://dummyurl/bar",
 
53
        :license      => "Apache2",
 
54
        :dependencies => [],
 
55
      }
 
56
    end
 
57
 
 
58
    context "when the module is not installed" do
 
59
      it "should fail" do
 
60
        @uninstaller.new('fakemod_not_installed', options).run[:result].should == :failure
 
61
      end
 
62
    end
 
63
 
 
64
    context "when the module is installed" do
 
65
 
 
66
      it "should uninstall the module" do
 
67
        PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
68
 
 
69
        results = @uninstaller.new("puppetlabs-foo", options).run
 
70
        results[:affected_modules].first.forge_name.should == "puppetlabs/foo"
 
71
      end
 
72
 
 
73
      it "should only uninstall the requested module" do
 
74
        PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
75
        PuppetSpec::Modules.create('bar', modpath1, :metadata => bar_metadata)
 
76
 
 
77
        results = @uninstaller.new("puppetlabs-foo", options).run
 
78
        results[:affected_modules].length == 1
 
79
        results[:affected_modules].first.forge_name.should == "puppetlabs/foo"
 
80
      end
 
81
 
 
82
      it "should uninstall fail if a module exists twice in the modpath" do
 
83
        PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
84
        PuppetSpec::Modules.create('foo', modpath2, :metadata => foo_metadata)
 
85
 
 
86
        @uninstaller.new('puppetlabs-foo', options).run[:result].should == :failure
 
87
      end
 
88
 
 
89
      context "when options[:version] is specified" do
 
90
 
 
91
        it "should uninstall the module if the version matches" do
 
92
          PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
93
 
 
94
          options[:version] = "1.0.0"
 
95
 
 
96
          results = @uninstaller.new("puppetlabs-foo", options).run
 
97
          results[:affected_modules].length.should == 1
 
98
          results[:affected_modules].first.forge_name.should == "puppetlabs/foo"
 
99
          results[:affected_modules].first.version.should == "1.0.0"
 
100
        end
 
101
 
 
102
        it "should not uninstall the module if the version does not match" do
 
103
          PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
104
 
 
105
          options[:version] = "2.0.0"
 
106
 
 
107
          @uninstaller.new("puppetlabs-foo", options).run[:result].should == :failure
 
108
        end
 
109
      end
 
110
 
 
111
      context "when the module metadata is missing" do
 
112
 
 
113
        it "should not uninstall the module" do
 
114
          PuppetSpec::Modules.create('foo', modpath1)
 
115
 
 
116
          @uninstaller.new("puppetlabs-foo", options).run[:result].should == :failure
 
117
        end
 
118
      end
 
119
 
 
120
      context "when the module has local changes" do
 
121
 
 
122
        it "should not uninstall the module" do
 
123
          PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
124
          Puppet::Module.any_instance.stubs(:has_local_changes?).returns(true)
 
125
 
 
126
          @uninstaller.new("puppetlabs-foo", options).run[:result].should == :failure
 
127
        end
 
128
 
 
129
      end
 
130
 
 
131
      context "when the module does not have local changes" do
 
132
 
 
133
        it "should uninstall the module" do
 
134
          PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
135
 
 
136
          results = @uninstaller.new("puppetlabs-foo", options).run
 
137
          results[:affected_modules].length.should == 1
 
138
          results[:affected_modules].first.forge_name.should == "puppetlabs/foo"
 
139
        end
 
140
      end
 
141
 
 
142
      context "when uninstalling the module will cause broken dependencies" do
 
143
        it "should not uninstall the module" do
 
144
          Puppet.settings[:modulepath] = modpath1
 
145
          PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
146
 
 
147
          PuppetSpec::Modules.create(
 
148
            'needy',
 
149
            modpath1,
 
150
            :metadata => {
 
151
              :author => 'beggar',
 
152
              :dependencies => [{
 
153
                  "version_requirement" => ">= 1.0.0",
 
154
                  "name" => "puppetlabs/foo"
 
155
              }]
 
156
            }
 
157
          )
 
158
 
 
159
          @uninstaller.new("puppetlabs-foo", options).run[:result].should == :failure
 
160
        end
 
161
      end
 
162
 
 
163
      context "when using the --force flag" do
 
164
 
 
165
        let(:fakemod) do
 
166
          stub(
 
167
            :forge_name => 'puppetlabs/fakemod',
 
168
            :version    => '0.0.1',
 
169
            :has_local_changes? => true
 
170
          )
 
171
        end
 
172
 
 
173
        it "should ignore local changes" do
 
174
          foo = mkmod("foo", modpath1, foo_metadata)
 
175
          options[:force] = true
 
176
 
 
177
          results = @uninstaller.new("puppetlabs-foo", options).run
 
178
          results[:affected_modules].length.should == 1
 
179
          results[:affected_modules].first.forge_name.should == "puppetlabs/foo"
 
180
        end
 
181
 
 
182
        it "should ignore broken dependencies" do
 
183
          Puppet.settings[:modulepath] = modpath1
 
184
          PuppetSpec::Modules.create('foo', modpath1, :metadata => foo_metadata)
 
185
 
 
186
          PuppetSpec::Modules.create(
 
187
            'needy',
 
188
            modpath1,
 
189
            :metadata => {
 
190
              :author => 'beggar',
 
191
              :dependencies => [{
 
192
                  "version_requirement" => ">= 1.0.0",
 
193
                  "name" => "puppetlabs/foo"
 
194
              }]
 
195
            }
 
196
          )
 
197
          options[:force] = true
 
198
 
 
199
          results = @uninstaller.new("puppetlabs-foo", options).run
 
200
          results[:affected_modules].length.should == 1
 
201
          results[:affected_modules].first.forge_name.should == "puppetlabs/foo"
 
202
        end
 
203
      end
 
204
    end
 
205
  end
 
206
end