summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Kearney <bkearney@redhat.com>2009-02-13 08:21:36 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-02-14 00:45:10 +1100
commit2a855510a3cca7d475c31495ccb502af606528dc (patch)
treeb9bc49f9f1daf542e0fdb5266c7c1d0e0dbd104b
parent2218611f7fa10b59945f65c80b05cbd8ebe137ef (diff)
downloadpuppet-2a855510a3cca7d475c31495ccb502af606528dc.tar.gz
puppet-2a855510a3cca7d475c31495ccb502af606528dc.tar.xz
puppet-2a855510a3cca7d475c31495ccb502af606528dc.zip
Bug 1948: Add logic and testing for the command parsing logic
-rw-r--r--lib/puppet/provider/augeas/augeas.rb11
-rw-r--r--spec/unit/provider/augeas/augeas.rb17
2 files changed, 19 insertions, 9 deletions
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index fd47da389..8d4f6d55a 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -52,7 +52,6 @@ Puppet::Type.type(:augeas).provide(:augeas) do
commands.concat(parse_commands(datum))
end
end
-
return commands
end
@@ -179,18 +178,20 @@ Puppet::Type.type(:augeas).provide(:augeas) do
debug("sending command '#{command}' with params #{cmd_array.inspect}")
aug.clear(cmd_array[0])
when "insert", "ins"
- if cmd_array.size < 3
+
+ ext_array = cmd_array[1].split(" ") ;
+ if cmd_array.size < 2 or ext_array.size < 2
fail("ins requires 3 parameters")
end
label = cmd_array[0]
- where = cmd_array[1]
- path = File.join(context, cmd_array[2])
+ where = ext_array[0]
+ path = File.join(context, ext_array[1])
case where
when "before": before = true
when "after": before = false
else fail("Invalid value '#{where}' for where param")
end
- debug("sending command '#{command}' with params #{[label, where, path]}")
+ debug("sending command '#{command}' with params #{[label, where, path].inspect()}")
aug.insert(path, label, before)
else fail("Command '#{command}' is not supported")
end
diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb
index 4bc1814e5..2def0d0c4 100644
--- a/spec/unit/provider/augeas/augeas.rb
+++ b/spec/unit/provider/augeas/augeas.rb
@@ -209,7 +209,7 @@ describe provider_class do
it "should handle ins commands with before" do
- command = [["ins", "Binks", "before", "/Jar/Jar"]]
+ command = [["ins", "Binks", "before /Jar/Jar"]]
context = "/foo"
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", true)
@@ -218,16 +218,25 @@ describe provider_class do
end
it "should handle ins commands with before" do
- command = [["ins", "Binks", "after", "/Jar/Jar"]]
+ command = [["ins", "Binks", "after /Jar/Jar"]]
context = "/foo"
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false)
@augeas.expects(:save).returns(true)
@provider.execute_changes.should == :executed
- end
+ end
+
+ it "should handle ins with no context" do
+ command = [["ins", "Binks", "after /Jar/Jar"]]
+ context = "" # this is the default
+ @resource.expects(:[]).times(2).returns(command).then.returns(context)
+ @augeas.expects(:insert).with("/Jar/Jar", "Binks", false)
+ @augeas.expects(:save).returns(true)
+ @provider.execute_changes.should == :executed
+ end
it "should handle multiple commands" do
- command = [["ins", "Binks", "after", "/Jar/Jar"], ["clear", "/Jar/Jar"]]
+ command = [["ins", "Binks", "after /Jar/Jar"], ["clear", "/Jar/Jar"]]
context = "/foo"
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false)