2012-07-20 02:37:39 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
2011-11-14 19:32:49 +01:00
|
|
|
require 'spec_helper'
|
2012-07-20 02:37:39 +02:00
|
|
|
|
2011-11-14 19:32:49 +01:00
|
|
|
describe Puppet::Parser::Functions.function(:get_module_path) do
|
2012-07-20 02:37:39 +02:00
|
|
|
Internals = PuppetlabsSpec::PuppetInternals
|
2012-07-24 00:47:51 +02:00
|
|
|
class StubModule
|
|
|
|
attr_reader :path
|
|
|
|
def initialize(path)
|
|
|
|
@path = path
|
|
|
|
end
|
|
|
|
end
|
2011-11-14 19:32:49 +01:00
|
|
|
|
2012-07-20 02:37:39 +02:00
|
|
|
def scope(environment = "production")
|
|
|
|
Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment)))
|
2011-11-14 19:32:49 +01:00
|
|
|
end
|
2012-07-20 02:37:39 +02:00
|
|
|
|
2011-11-14 19:32:49 +01:00
|
|
|
it 'should only allow one argument' do
|
2012-10-16 12:54:14 +02:00
|
|
|
expect { scope.function_get_module_path([]) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
|
|
|
|
expect { scope.function_get_module_path(['1','2','3']) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
|
2011-11-14 19:32:49 +01:00
|
|
|
end
|
|
|
|
it 'should raise an exception when the module cannot be found' do
|
2012-10-16 12:54:14 +02:00
|
|
|
expect { scope.function_get_module_path(['foo']) }.to raise_error(Puppet::ParseError, /Could not find module/)
|
2011-11-14 19:32:49 +01:00
|
|
|
end
|
|
|
|
describe 'when locating a module' do
|
2012-07-20 02:37:39 +02:00
|
|
|
let(:modulepath) { "/tmp/does_not_exist" }
|
2012-07-24 00:47:51 +02:00
|
|
|
let(:path_of_module_foo) { StubModule.new("/tmp/does_not_exist/foo") }
|
2012-07-20 02:37:39 +02:00
|
|
|
|
|
|
|
before(:each) { Puppet[:modulepath] = modulepath }
|
|
|
|
|
2011-11-14 19:32:49 +01:00
|
|
|
it 'should be able to find module paths from the modulepath setting' do
|
2012-07-20 02:37:39 +02:00
|
|
|
Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
|
2011-11-14 19:32:49 +01:00
|
|
|
end
|
|
|
|
it 'should be able to find module paths when the modulepath is a list' do
|
|
|
|
Puppet[:modulepath] = modulepath + ":/tmp"
|
2012-07-20 02:37:39 +02:00
|
|
|
Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
|
2011-11-14 19:32:49 +01:00
|
|
|
end
|
2012-07-20 02:37:39 +02:00
|
|
|
it 'should respect the environment' do
|
2014-06-04 20:38:37 +02:00
|
|
|
skip("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/
|
2012-07-20 02:37:39 +02:00
|
|
|
Puppet.settings[:environment] = 'danstestenv'
|
|
|
|
Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo)
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(scope('danstestenv').function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
|
2011-11-14 19:32:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|