source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/spec/functions/validate_augeas_spec.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 8 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1require 'spec_helper'
2
3describe 'validate_augeas' do
4 unless Puppet.features.augeas?
5 skip "ruby-augeas not installed"
6 else
7 describe 'signature validation' do
8 it { is_expected.not_to eq(nil) }
9 it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
10 it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
11 it { is_expected.to run.with_params('', '', [], '', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
12 it { is_expected.to run.with_params('one', 'one', 'MSG to User', '4th arg').and_raise_error(NoMethodError) }
13 end
14
15 describe 'valid inputs' do
16 inputs = [
17 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ],
18 [ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
19 ]
20
21 inputs.each do |input|
22 it { is_expected.to run.with_params(*input) }
23 end
24 end
25
26 describe 'valid inputs which fail augeas validation' do
27 # The intent here is to make sure valid inputs raise exceptions when they
28 # don't specify an error message to display. This is the behvior in
29 # 2.2.x and prior.
30 inputs = [
31 [ "root:x:0:0:root\n", 'Passwd.lns' ],
32 [ "127.0.1.1\n", 'Hosts.lns' ],
33 ]
34
35 inputs.each do |input|
36 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /validate_augeas.*?matched less than it should/) }
37 end
38 end
39
40 describe "when specifying nice error messages" do
41 # The intent here is to make sure the function returns the 4th argument
42 # in the exception thrown
43 inputs = [
44 [ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ],
45 [ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ],
46 ]
47
48 inputs.each do |input|
49 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /#{input[3]}/) }
50 end
51 end
52
53 describe "matching additional tests" do
54 inputs = [
55 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
56 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
57 ]
58
59 inputs.each do |input|
60 it { is_expected.to run.with_params(*input) }
61 end
62 end
63
64 describe "failing additional tests" do
65 inputs = [
66 [ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
67 [ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
68 ]
69
70 inputs.each do |input|
71 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /testing path/) }
72 end
73 end
74 end
75end
Note: See TracBrowser for help on using the repository browser.