1 #! /usr/bin/env ruby -S rspec
4 describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 # The subject of these examplres is the method itself.
9 # This makes sure the function is loaded within each test
10 function_name = Puppet::Parser::Functions.function(:validate_augeas)
11 scope.method(function_name)
14 context 'Using Puppet::Parser::Scope.new' do
16 describe 'Garbage inputs' do
20 [ { 'foo' => 'bar' } ],
23 [ "one", "one", "MSG to User", "4th arg" ],
26 inputs.each do |input|
27 it "validate_augeas(#{input.inspect}) should fail" do
28 expect { subject.call [input] }.to raise_error Puppet::ParseError
33 describe 'Valid inputs' do
35 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ],
36 [ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
39 inputs.each do |input|
40 it "validate_augeas(#{input.inspect}) should not fail" do
41 expect { subject.call input }.not_to raise_error
46 describe "Valid inputs which should raise an exception without a message" do
47 # The intent here is to make sure valid inputs raise exceptions when they
48 # don't specify an error message to display. This is the behvior in
51 [ "root:x:0:0:root\n", 'Passwd.lns' ],
52 [ "127.0.1.1\n", 'Hosts.lns' ],
55 inputs.each do |input|
56 it "validate_augeas(#{input.inspect}) should fail" do
57 expect { subject.call input }.to raise_error /validate_augeas.*?matched less than it should/
62 describe "Nicer Error Messages" do
63 # The intent here is to make sure the function returns the 4th argument
64 # in the exception thrown
66 [ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ],
67 [ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ],
70 inputs.each do |input|
71 it "validate_augeas(#{input.inspect}) should fail" do
72 expect { subject.call input }.to raise_error /#{input[3]}/
77 describe "Passing simple unit tests" do
79 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
80 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
83 inputs.each do |input|
84 it "validate_augeas(#{input.inspect}) should fail" do
85 expect { subject.call input }.not_to raise_error
90 describe "Failing simple unit tests" do
92 [ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
93 [ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
96 inputs.each do |input|
97 it "validate_augeas(#{input.inspect}) should fail" do
98 expect { subject.call input }.to raise_error /testing path/