|
1 |
| -#!/usr/bin/env rspec |
2 |
| -require 'puppet' |
3 |
| -require 'fileutils' |
| 1 | +#! /usr/bin/env ruby -S rspec |
4 | 2 | require 'spec_helper'
|
| 3 | + |
5 | 4 | describe Puppet::Parser::Functions.function(:get_module_path) do
|
6 |
| - include PuppetSpec::Files |
| 5 | + Internals = PuppetlabsSpec::PuppetInternals |
7 | 6 |
|
8 |
| - def get_scope(environment = 'production') |
9 |
| - scope = Puppet::Parser::Scope.new |
10 |
| - scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("floppy", :environment => environment)) |
11 |
| - scope |
| 7 | + def scope(environment = "production") |
| 8 | + Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment))) |
12 | 9 | end
|
| 10 | + |
13 | 11 | it 'should only allow one argument' do
|
14 |
| - expect { get_scope.function_get_module_path([]) }.should raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) |
15 |
| - expect { get_scope.function_get_module_path(['1','2','3']) }.should raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) |
| 12 | + expect { scope.function_get_module_path([]) }.should raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) |
| 13 | + expect { scope.function_get_module_path(['1','2','3']) }.should raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) |
16 | 14 | end
|
17 | 15 | it 'should raise an exception when the module cannot be found' do
|
18 |
| - expect { get_scope.function_get_module_path(['foo']) }.should raise_error(Puppet::ParseError, /Could not find module/) |
| 16 | + expect { scope.function_get_module_path(['foo']) }.should raise_error(Puppet::ParseError, /Could not find module/) |
19 | 17 | end
|
20 | 18 | describe 'when locating a module' do
|
21 |
| - let(:modulepath) { tmpdir('modulepath') } |
22 |
| - let(:foo_path) { File.join(modulepath, 'foo') } |
23 |
| - before(:each) { FileUtils.mkdir(foo_path) } |
| 19 | + let(:modulepath) { "/tmp/does_not_exist" } |
| 20 | + let(:path_of_module_foo) do |
| 21 | + mod = mock("Puppet::Module") |
| 22 | + mod.stubs(:path).returns("/tmp/does_not_exist/foo") |
| 23 | + mod |
| 24 | + end |
| 25 | + |
| 26 | + before(:each) { Puppet[:modulepath] = modulepath } |
| 27 | + |
24 | 28 | it 'should be able to find module paths from the modulepath setting' do
|
25 |
| - Puppet[:modulepath] = modulepath |
26 |
| - get_scope.function_get_module_path(['foo']).should == foo_path |
| 29 | + Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo) |
| 30 | + scope.function_get_module_path(['foo']).should == path_of_module_foo.path |
27 | 31 | end
|
28 | 32 | it 'should be able to find module paths when the modulepath is a list' do
|
29 | 33 | Puppet[:modulepath] = modulepath + ":/tmp"
|
30 |
| - get_scope.function_get_module_path(['foo']).should == foo_path |
| 34 | + Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo) |
| 35 | + scope.function_get_module_path(['foo']).should == path_of_module_foo.path |
31 | 36 | end
|
32 |
| - it 'should be able to find module paths from the environment' do |
33 |
| - conf_file = tmpfile('conffile') |
34 |
| - File.open(conf_file, 'w') do |fh| |
35 |
| - fh.write("[dansenvironment]\nmodulepath = #{modulepath}") |
36 |
| - end |
37 |
| - Puppet[:config] = conf_file |
38 |
| - Puppet.parse_config |
39 |
| - get_scope('dansenvironment').function_get_module_path(['foo']).should ==foo_path |
| 37 | + it 'should respect the environment' do |
| 38 | + pending("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/ |
| 39 | + Puppet.settings[:environment] = 'danstestenv' |
| 40 | + Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo) |
| 41 | + scope('danstestenv').function_get_module_path(['foo']).should == path_of_module_foo.path |
40 | 42 | end
|
41 | 43 | end
|
42 | 44 | end
|
0 commit comments