Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_absolute_path_spec.rb
1 require 'spec_helper'
2
3 describe 'validate_absolute_path' do
4   after(:each) do
5     ENV.delete('STDLIB_LOG_DEPRECATIONS')
6   end
7
8   # Checking for deprecation warning
9   it 'displays a single deprecation' do
10     ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
11     expect(scope).to receive(:warning).with(include('This method is deprecated'))
12     is_expected.to run.with_params('c:/')
13   end
14
15   describe 'signature validation' do
16     it { is_expected.not_to eq(nil) }
17     it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
18   end
19
20   describe 'valid paths handling' do
21     ['C:/', 'C:\\', 'C:\\WINDOWS\\System32', 'C:/windows/system32', 'X:/foo/bar', 'X:\\foo\\bar', '\\\\host\\windows', '//host/windows', '/', '/var/tmp', '/var/opt/../lib/puppet'].each do |path|
22       it { is_expected.to run.with_params(path) }
23       it { is_expected.to run.with_params(['/tmp', path]) }
24     end
25   end
26
27   describe 'invalid path handling' do
28     context 'with garbage inputs' do
29       [
30         nil,
31         [nil],
32         [nil, nil],
33         { 'foo' => 'bar' },
34         {},
35         '',
36       ].each do |path|
37         it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
38         it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
39         it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
40       end
41     end
42
43     context 'with relative paths' do
44       ['relative1', '.', '..', './foo', '../foo', 'etc/puppetlabs/puppet', 'relative\\windows'].each do |path|
45         it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
46         it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
47         it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
48       end
49     end
50   end
51 end