1 | require 'spec_helper'
|
---|
2 |
|
---|
3 | describe 'validate_absolute_path' do
|
---|
4 | after(:all) do
|
---|
5 | ENV.delete('STDLIB_LOG_DEPRECATIONS')
|
---|
6 | end
|
---|
7 |
|
---|
8 | # Checking for deprecation warning
|
---|
9 | it 'should display a single deprecation' do
|
---|
10 | ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
|
---|
11 | scope.expects(:warning).with(includes('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, /wrong number of arguments/i) }
|
---|
18 | end
|
---|
19 |
|
---|
20 | describe "valid paths handling" do
|
---|
21 | %w{
|
---|
22 | C:/
|
---|
23 | C:\\
|
---|
24 | C:\\WINDOWS\\System32
|
---|
25 | C:/windows/system32
|
---|
26 | X:/foo/bar
|
---|
27 | X:\\foo\\bar
|
---|
28 | \\\\host\\windows
|
---|
29 | //host/windows
|
---|
30 | /
|
---|
31 | /var/tmp
|
---|
32 | /var/opt/../lib/puppet
|
---|
33 | }.each do |path|
|
---|
34 | it { is_expected.to run.with_params(path) }
|
---|
35 | it { is_expected.to run.with_params(['/tmp', path]) }
|
---|
36 | end
|
---|
37 | end
|
---|
38 |
|
---|
39 | describe 'invalid path handling' do
|
---|
40 | context 'garbage inputs' do
|
---|
41 | [
|
---|
42 | nil,
|
---|
43 | [ nil ],
|
---|
44 | [ nil, nil ],
|
---|
45 | { 'foo' => 'bar' },
|
---|
46 | { },
|
---|
47 | '',
|
---|
48 | ].each do |path|
|
---|
49 | it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, /is not an absolute path/) }
|
---|
50 | it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, /is not an absolute path/) }
|
---|
51 | it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, /is not an absolute path/) }
|
---|
52 | end
|
---|
53 | end
|
---|
54 |
|
---|
55 | context 'relative paths' do
|
---|
56 | %w{
|
---|
57 | relative1
|
---|
58 | .
|
---|
59 | ..
|
---|
60 | ./foo
|
---|
61 | ../foo
|
---|
62 | etc/puppetlabs/puppet
|
---|
63 | opt/puppet/bin
|
---|
64 | relative\\windows
|
---|
65 | }.each do |path|
|
---|
66 | it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, /is not an absolute path/) }
|
---|
67 | it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, /is not an absolute path/) }
|
---|
68 | it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, /is not an absolute path/) }
|
---|
69 | end
|
---|
70 | end
|
---|
71 | end
|
---|
72 | end
|
---|
73 |
|
---|