]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/validate_absolute_path_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_absolute_path_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe Puppet::Parser::Functions.function(:validate_absolute_path) do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   # The subject of these examples is the method itself.
8   subject do
9     # This makes sure the function is loaded within each test
10     function_name = Puppet::Parser::Functions.function(:validate_absolute_path)
11     scope.method(function_name)
12   end
13
14   describe "Valid Paths" do
15     def self.valid_paths
16       %w{
17         C:/
18         C:\\
19         C:\\WINDOWS\\System32
20         C:/windows/system32
21         X:/foo/bar
22         X:\\foo\\bar
23         /var/tmp
24         /var/lib/puppet
25         /var/opt/../lib/puppet
26       }
27     end
28
29     context "Without Puppet::Util.absolute_path? (e.g. Puppet <= 2.6)" do
30       before :each do
31         # The intent here is to mock Puppet to behave like Puppet 2.6 does.
32         # Puppet 2.6 does not have the absolute_path? method.  This is only a
33         # convenience test, stdlib should be run with the Puppet 2.6.x in the
34         # $LOAD_PATH in addition to 2.7.x and master.
35         Puppet::Util.expects(:respond_to?).with(:absolute_path?).returns(false)
36       end
37       valid_paths.each do |path|
38         it "validate_absolute_path(#{path.inspect}) should not fail" do
39           expect { subject.call [path] }.not_to raise_error
40         end
41       end
42       valid_paths do
43         it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do
44           expect { subject.call [valid_paths] }.not_to raise_error
45         end
46       end
47     end
48
49     context "Puppet without mocking" do
50       valid_paths.each do |path|
51         it "validate_absolute_path(#{path.inspect}) should not fail" do
52           expect { subject.call [path] }.not_to raise_error
53         end
54       end
55       valid_paths do
56         it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do
57           expect { subject.call [valid_paths] }.not_to raise_error
58         end
59       end
60     end
61   end
62
63   describe 'Invalid paths' do
64     context 'Garbage inputs' do
65       [
66         nil,
67         [ nil ],
68         [ nil, nil ],
69         { 'foo' => 'bar' },
70         { },
71         '',
72       ].each do |path|
73         it "validate_absolute_path(#{path.inspect}) should fail" do
74           expect { subject.call [path] }.to raise_error Puppet::ParseError
75         end
76       end
77     end
78
79     context 'Relative paths' do
80       def self.rel_paths 
81         %w{
82           relative1
83           .
84           ..
85           ./foo
86           ../foo
87           etc/puppetlabs/puppet
88           opt/puppet/bin
89         }
90       end
91       rel_paths.each do |path|
92         it "validate_absolute_path(#{path.inspect}) should fail" do
93           expect { subject.call [path] }.to raise_error Puppet::ParseError
94         end
95       end
96       rel_paths do
97         it "validate_absolute_path(#{rel_paths.inspect}) should fail" do
98           expect { subject.call [rel_paths] }.to raise_error Puppet::ParseError
99         end
100       end
101     end
102   end
103 end
104