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

« back to all changes in this revision

Viewing changes to spec/unit/face/module/install_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/face'
 
3
require 'puppet/module_tool'
 
4
 
 
5
describe "puppet module install" do
 
6
  include PuppetSpec::Files
 
7
 
 
8
  subject { Puppet::Face[:module, :current] }
 
9
 
 
10
  let(:options) do
 
11
    {}
 
12
  end
 
13
 
 
14
  describe "option validation" do
 
15
    before do
 
16
      Puppet.settings[:modulepath] = fakemodpath
 
17
    end
 
18
 
 
19
    let(:expected_options) do
 
20
      {
 
21
        :target_dir  => fakefirstpath,
 
22
        :modulepath  => fakemodpath,
 
23
        :environment => 'production'
 
24
      }
 
25
    end
 
26
 
 
27
    let(:sep) { File::PATH_SEPARATOR }
 
28
    let(:fakefirstpath)  { make_absolute("/my/fake/modpath") }
 
29
    let(:fakesecondpath) { make_absolute("/other/fake/path") }
 
30
    let(:fakemodpath)    { "#{fakefirstpath}#{sep}#{fakesecondpath}" }
 
31
    let(:fakedirpath)    { make_absolute("/my/fake/path") }
 
32
 
 
33
    context "without any options" do
 
34
      it "should require a name" do
 
35
        pattern = /wrong number of arguments/
 
36
        expect { subject.install }.to raise_error ArgumentError, pattern
 
37
      end
 
38
 
 
39
      it "should not require any options" do
 
40
        Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
 
41
        subject.install("puppetlabs-apache")
 
42
      end
 
43
    end
 
44
 
 
45
    it "should accept the --force option" do
 
46
      options[:force] = true
 
47
      expected_options.merge!(options)
 
48
      Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
 
49
      subject.install("puppetlabs-apache", options)
 
50
    end
 
51
 
 
52
    it "should accept the --target-dir option" do
 
53
      options[:target_dir] = make_absolute("/foo/puppet/modules")
 
54
      expected_options.merge!(options)
 
55
      expected_options[:modulepath] = "#{options[:target_dir]}#{sep}#{fakemodpath}"
 
56
 
 
57
      Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
 
58
      subject.install("puppetlabs-apache", options)
 
59
    end
 
60
 
 
61
    it "should accept the --version option" do
 
62
      options[:version] = "0.0.1"
 
63
      expected_options.merge!(options)
 
64
      Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
 
65
      subject.install("puppetlabs-apache", options)
 
66
    end
 
67
 
 
68
    it "should accept the --ignore-dependencies option" do
 
69
      options[:ignore_dependencies] = true
 
70
      expected_options.merge!(options)
 
71
      Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
 
72
      subject.install("puppetlabs-apache", options)
 
73
    end
 
74
 
 
75
    describe "when modulepath option is passed" do
 
76
      let(:expected_options) { { :modulepath => fakemodpath, :environment => 'production' } }
 
77
      let(:options)          { { :modulepath => fakemodpath } }
 
78
 
 
79
      describe "when target-dir option is not passed" do
 
80
        it "should set target-dir to be first path from modulepath" do
 
81
          expected_options[:target_dir] = fakefirstpath
 
82
 
 
83
          Puppet::ModuleTool::Applications::Installer.
 
84
            expects(:run).
 
85
            with("puppetlabs-apache", expected_options)
 
86
 
 
87
          Puppet::Face[:module, :current].install("puppetlabs-apache", options)
 
88
 
 
89
          Puppet.settings[:modulepath].should == fakemodpath
 
90
        end
 
91
      end
 
92
 
 
93
      describe "when target-dir option is passed" do
 
94
        it "should expand the target directory" do
 
95
          options[:target_dir] = "modules"
 
96
          expanded_path = File.expand_path("modules")
 
97
          expected_options.merge!(options)
 
98
          expected_options[:target_dir] = expanded_path
 
99
          expected_options[:modulepath] = "#{expanded_path}#{sep}#{fakemodpath}"
 
100
 
 
101
          Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
 
102
          subject.install("puppetlabs-apache", options)
 
103
        end
 
104
 
 
105
        it "should set target-dir to be first path of modulepath" do
 
106
          options[:target_dir] = fakedirpath
 
107
          expected_options[:target_dir] = fakedirpath
 
108
          expected_options[:modulepath] = "#{fakedirpath}#{sep}#{fakemodpath}"
 
109
 
 
110
          Puppet::ModuleTool::Applications::Installer.
 
111
            expects(:run).
 
112
            with("puppetlabs-apache", expected_options)
 
113
 
 
114
          Puppet::Face[:module, :current].install("puppetlabs-apache", options)
 
115
 
 
116
          Puppet.settings[:modulepath].should == "#{fakedirpath}#{sep}#{fakemodpath}"
 
117
        end
 
118
      end
 
119
    end
 
120
 
 
121
    describe "when modulepath option is not passed" do
 
122
      before do
 
123
        Puppet.settings[:modulepath] = fakemodpath
 
124
      end
 
125
 
 
126
      describe "when target-dir option is not passed" do
 
127
        it "should set target-dir to be first path of default mod path" do
 
128
          expected_options[:target_dir] = fakefirstpath
 
129
          expected_options[:modulepath] = fakemodpath
 
130
 
 
131
          Puppet::ModuleTool::Applications::Installer.
 
132
            expects(:run).
 
133
            with("puppetlabs-apache", expected_options)
 
134
 
 
135
          Puppet::Face[:module, :current].install("puppetlabs-apache", options)
 
136
        end
 
137
      end
 
138
 
 
139
      describe "when target-dir option is passed" do
 
140
        it "should prepend target-dir to modulepath" do
 
141
          options[:target_dir] = fakedirpath
 
142
          expected_options[:target_dir] = fakedirpath
 
143
          expected_options[:modulepath] = "#{options[:target_dir]}#{sep}#{fakemodpath}"
 
144
 
 
145
          Puppet::ModuleTool::Applications::Installer.
 
146
            expects(:run).
 
147
            with("puppetlabs-apache", expected_options)
 
148
 
 
149
          Puppet::Face[:module, :current].install("puppetlabs-apache", options)
 
150
          Puppet.settings[:modulepath].should == expected_options[:modulepath]
 
151
        end
 
152
      end
 
153
    end
 
154
  end
 
155
 
 
156
  describe "inline documentation" do
 
157
    subject { Puppet::Face[:module, :current].get_action :install }
 
158
 
 
159
    its(:summary)     { should =~ /install.*module/im }
 
160
    its(:description) { should =~ /install.*module/im }
 
161
    its(:returns)     { should =~ /pathname/i }
 
162
    its(:examples)    { should_not be_empty }
 
163
 
 
164
    %w{ license copyright summary description returns examples }.each do |doc|
 
165
      context "of the" do
 
166
        its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ }
 
167
      end
 
168
    end
 
169
  end
 
170
end