aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMelissa Stone <melissa@puppet.com>2018-08-15 14:17:13 -0700
committerMelissa Stone <melissa@puppet.com>2018-08-15 14:17:13 -0700
commit25496ce72baf751d2c7c6a54c536679256471b75 (patch)
tree36fd96b32c3747e3a37be1f9ae4acd361be98fca /spec
parente85283b0f41ae1635954c76b2978e34c260794cd (diff)
parent22fd1a59f1f97372144c62056adfcd20ec82ea07 (diff)
downloadpuppet-augeas_core-25496ce72baf751d2c7c6a54c536679256471b75.tar.gz
puppet-augeas_core-25496ce72baf751d2c7c6a54c536679256471b75.tar.bz2
Merge remote-tracking branch 'upstream/master' into release
Diffstat (limited to 'spec')
-rw-r--r--spec/spec_helper_acceptance.rb2
-rw-r--r--spec/unit/provider/augeas/augeas_spec.rb65
-rw-r--r--spec/unit/puppet_x/augeas/util/parser_spec.rb110
3 files changed, 176 insertions, 1 deletions
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
index 848f7d9..a6836f2 100644
--- a/spec/spec_helper_acceptance.rb
+++ b/spec/spec_helper_acceptance.rb
@@ -6,7 +6,7 @@ RSpec.configure do |c|
c.before :suite do
unless ENV['BEAKER_provision'] == 'no'
run_puppet_install_helper
- install_module_on(hosts_as('default'))
+ install_module_on(hosts)
install_module_dependencies_on(hosts)
end
end
diff --git a/spec/unit/provider/augeas/augeas_spec.rb b/spec/unit/provider/augeas/augeas_spec.rb
index 6166140..180f89c 100644
--- a/spec/unit/provider/augeas/augeas_spec.rb
+++ b/spec/unit/provider/augeas/augeas_spec.rb
@@ -262,6 +262,49 @@ describe Puppet::Type.type(:augeas).provider(:augeas) do
command = ['values', 'fake value', "== ['set', 'of', 'values']"]
expect(provider.process_values(command)).to eq(true)
end
+ it 'returns true for an array match with double quotes and spaces' do
+ command = ['values', 'fake value', '== [ "set" , "of" , "values" ] ']
+ expect(provider.process_values(command)).to eq(true)
+ end
+
+ it 'returns true for an array match with internally escaped single quotes' do
+ provider.aug.stubs(:match).returns(['set', "o'values", 'here'])
+ provider.aug.stubs(:get).returns('set').then.returns("o'values").then.returns('here')
+ command = ['values', 'fake value', "== [ 'set', 'o\\'values', 'here']"]
+ expect(provider.process_values(command)).to eq(true)
+ end
+
+ it 'returns true for an array match with octal character sequences' do
+ command = ['values', 'fake value', '== ["\\x73et", "of", "values"]']
+ expect(provider.process_values(command)).to eq(true)
+ end
+
+ it 'returns true for an array match with hex character sequences' do
+ command = ['values', 'fake value', '== ["\\163et", "of", "values"]']
+ expect(provider.process_values(command)).to eq(true)
+ end
+
+ it 'returns true for an array match with short unicode escape sequences' do
+ command = ['values', 'fake value', '== ["\\u0073et", "of", "values"]']
+ expect(provider.process_values(command)).to eq(true)
+ end
+
+ it 'returns true for an array match with single character long unicode escape sequences' do
+ command = ['values', 'fake value', '== ["\\u{0073}et", "of", "values"]']
+ expect(provider.process_values(command)).to eq(true)
+ end
+
+ it 'returns true for an array match with multi-character long unicode escape sequences' do
+ command = ['values', 'fake value', '== ["\\u{0073 0065 0074}", "of", "values"]']
+ expect(provider.process_values(command)).to eq(true)
+ end
+
+ it 'returns true for an array match with literal backslashes' do
+ provider.aug.stubs(:match).returns(['set', 'o\\values', 'here'])
+ provider.aug.stubs(:get).returns('set').then.returns('o\\values').then.returns('here')
+ command = ['values', 'fake value', '== [ "set", "o\\\\values", "here"]']
+ expect(provider.process_values(command)).to eq(true)
+ end
it 'returns false for an array non match' do
command = ['values', 'fake value', "== ['this', 'should', 'not', 'match']"]
@@ -277,6 +320,18 @@ describe Puppet::Type.type(:augeas).provider(:augeas) do
command = ['values', 'fake value', "!= ['this', 'should', 'not', 'match']"]
expect(provider.process_values(command)).to eq(true)
end
+
+ it 'returns true for an array non match with double quotes and spaces' do
+ command = ['values', 'fake value', '!= [ "this" , "should" ,"not", "match" ] ']
+ expect(provider.process_values(command)).to eq(true)
+ end
+
+ it 'returns true for an empty array match' do
+ provider.aug.stubs(:match).returns([])
+ provider.aug.stubs(:get)
+ command = ['values', 'fake value', '== []']
+ expect(provider.process_values(command)).to eq(true)
+ end
end
describe 'match filters' do
@@ -322,6 +377,11 @@ describe Puppet::Type.type(:augeas).provider(:augeas) do
expect(provider.process_match(command)).to eq(true)
end
+ it 'returns true for an array match with double quotes and spaces' do
+ command = ['match', 'fake value', '== [ "set" , "of" , "values" ] ']
+ expect(provider.process_match(command)).to eq(true)
+ end
+
it 'returns false for an array non match' do
command = ['match', 'fake value', "== ['this', 'should', 'not', 'match']"]
expect(provider.process_match(command)).to eq(false)
@@ -336,6 +396,11 @@ describe Puppet::Type.type(:augeas).provider(:augeas) do
command = ['match', 'fake value', "!= ['this', 'should', 'not', 'match']"]
expect(provider.process_match(command)).to eq(true)
end
+
+ it 'returns true for an array non match with double quotes and spaces' do
+ command = ['match', 'fake value', '!= [ "this" , "should" ,"not", "match" ] ']
+ expect(provider.process_match(command)).to eq(true)
+ end
end
describe 'need to run' do
diff --git a/spec/unit/puppet_x/augeas/util/parser_spec.rb b/spec/unit/puppet_x/augeas/util/parser_spec.rb
new file mode 100644
index 0000000..f8b5b2b
--- /dev/null
+++ b/spec/unit/puppet_x/augeas/util/parser_spec.rb
@@ -0,0 +1,110 @@
+require 'spec_helper'
+require 'puppet_x/augeas/util/parser'
+
+describe PuppetX::Augeas::Util::Parser do
+ include described_class
+
+ it 'handles an empty array' do
+ expect(parse_to_array('[]')).to eq([])
+ end
+
+ it 'handles an array with a simple single-quoted entry' do
+ expect(parse_to_array("['entry']")).to eq(['entry'])
+ end
+
+ it 'handles an array with a simple double-quoted entry' do
+ expect(parse_to_array('["entry"]')).to eq(['entry'])
+ end
+
+ it 'handles an array with both single- and double-quoted entries' do
+ expect(parse_to_array(%q(['first', "second"]))).to eq(['first', 'second'])
+ end
+
+ context 'inside single-quoted strings' do
+ it 'allows a literal backslash' do
+ expect(parse_to_array("['entry\\\\here']")).to eq(['entry\\here'])
+ end
+
+ it 'allows an internal single-quote' do
+ expect(parse_to_array("['entry\\'here']")).to eq(['entry\'here'])
+ end
+ end
+
+ context 'inside double-quoted strings' do
+ it 'allows a literal backslash' do
+ expect(parse_to_array('["entry\\\\here"]')).to eq(['entry\\here'])
+ end
+
+ it 'allows an internal double-quote' do
+ expect(parse_to_array('["entry\\"here"]')).to eq(['entry"here'])
+ end
+
+ it 'does not require escaping a single-quote' do
+ expect(parse_to_array('["entry\'here"]')).to eq(["entry'here"])
+ end
+
+ it 'allows a bell character escape' do
+ expect(parse_to_array('["entry\\ahere"]')).to eq(["entry\ahere"])
+ end
+
+ it 'allows a backspace character escape' do
+ expect(parse_to_array('["entry\\bhere"]')).to eq(["entry\bhere"])
+ end
+
+ it 'allows a horizontal tab character escape' do
+ expect(parse_to_array('["entry\\there"]')).to eq(["entry\there"])
+ end
+
+ it 'allows a line feed character escape' do
+ expect(parse_to_array('["entry\\nhere"]')).to eq(["entry\nhere"])
+ end
+
+ it 'allows a vertical tab character escape' do
+ expect(parse_to_array('["entry\\vhere"]')).to eq(["entry\vhere"])
+ end
+
+ it 'allows a form feed character escape' do
+ expect(parse_to_array('["entry\\fhere"]')).to eq(["entry\fhere"])
+ end
+
+ it 'allows a carriage return character escape' do
+ expect(parse_to_array('["entry\\rhere"]')).to eq(["entry\rhere"])
+ end
+
+ it 'allows an escape character escape' do
+ expect(parse_to_array('["entry\\ehere"]')).to eq(["entry\ehere"])
+ end
+
+ it 'allows a space character escape' do
+ expect(parse_to_array('["entry\\shere"]')).to eq(['entry here'])
+ end
+
+ it 'allows octal character escapes' do
+ expect(parse_to_array('["\7", "\41", "\101", "\1411"]')).to eq(["\a", '!', 'A', 'a1'])
+ end
+
+ it 'allows hexadecimal character escapes with \\x' do
+ expect(parse_to_array('["\x7", "\x21", "\x211"]')).to eq(["\a", '!', '!1'])
+ end
+
+ it 'allows single-character unicode hexadecimal character escapes with \\u' do
+ expect(parse_to_array('["\u2015", "\u20222"]')).to eq(["\u2015", "\u2022" << '2'])
+ end
+
+ it 'allows multi-character unicode hexadecimal character escapes with \\u{...}' do
+ expect(parse_to_array('["\u{7}", "\u{20}", "\u{100}", "\u{2026}", "\u{1F464}", "\u{100000}", "\u{53 74 72 69 6E 67}"]')).to eq(["\a", ' ', "\u{100}", "\u{2026}", "\u{1F464}", "\u{100000}", 'String'])
+ end
+ end
+
+ it 'fails with garbage in front of the array' do
+ expect { parse_to_array("junk ['good', 'array', 'here']") }.to raise_error(RuntimeError, %r{^Unexpected character in array at: junk \['good})
+ end
+
+ it 'fails with garbage in the middle of the array' do
+ expect { parse_to_array("['got', 'some', junk 'here']") }.to raise_error(RuntimeError, %r{^Unexpected character in array at: junk 'here'})
+ end
+
+ it 'fails with garbage after the array' do
+ expect { parse_to_array("['good', 'array', 'here'] junk after") }.to raise_error(RuntimeError, %r{^Unexpected character in array at: junk after})
+ end
+end