spec/unit/provider/augeas/augeas.rb in puppet-0.24.9 vs spec/unit/provider/augeas/augeas.rb in puppet-0.25.0
- old
+ new
@@ -3,42 +3,55 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
provider_class = Puppet::Type.type(:augeas).provider(:augeas)
describe provider_class do
-
+
describe "command parsing" do
before do
- @resource = stub("resource")
+ @resource = stub("resource")
@provider = provider_class.new(@resource)
end
-
+
it "should break apart a single line into three tokens and clean up the context" do
- @resource.stubs(:[]).returns("/context")
- tokens = @provider.parse_commands("set Jar/Jar Binks")
+ @resource.stubs(:[]).returns("/context")
+ tokens = @provider.parse_commands("set Jar/Jar Binks")
tokens.size.should == 1
tokens[0].size.should == 3
tokens[0][0].should == "set"
tokens[0][1].should == "/context/Jar/Jar"
tokens[0][2].should == "Binks"
end
it "should break apart a multiple line into six tokens" do
- @resource.stubs(:[]).returns("")
- tokens = @provider.parse_commands("set /Jar/Jar Binks\nrm anakin")
+ @resource.stubs(:[]).returns("")
+ tokens = @provider.parse_commands("set /Jar/Jar Binks\nrm anakin")
tokens.size.should == 2
tokens[0].size.should == 3
tokens[1].size.should == 2
tokens[0][0].should == "set"
tokens[0][1].should == "/Jar/Jar"
tokens[0][2].should == "Binks"
tokens[1][0].should == "rm"
tokens[1][1].should == "anakin"
end
+ it "should strip whitespace and ignore blank lines" do
+ @resource.stubs(:[]).returns("")
+ tokens = @provider.parse_commands(" set /Jar/Jar Binks \t\n \n\n rm anakin ")
+ tokens.size.should == 2
+ tokens[0].size.should == 3
+ tokens[1].size.should == 2
+ tokens[0][0].should == "set"
+ tokens[0][1].should == "/Jar/Jar"
+ tokens[0][2].should == "Binks"
+ tokens[1][0].should == "rm"
+ tokens[1][1].should == "anakin"
+ end
+
it "should handle arrays" do
- @resource.stubs(:[]).returns("/foo/")
+ @resource.stubs(:[]).returns("/foo/")
commands = ["set /Jar/Jar Binks", "rm anakin"]
tokens = @provider.parse_commands(commands)
tokens.size.should == 2
tokens[0].size.should == 3
tokens[1].size.should == 2
@@ -59,68 +72,82 @@
# tokens[0][1].should == "/Jar/Jar"
# tokens[0][2].should == "Binks is my copilot"
#end
it "should accept spaces in the value and single ticks" do
- @resource.stubs(:[]).returns("/foo/")
+ @resource.stubs(:[]).returns("/foo/")
tokens = @provider.parse_commands("set JarJar 'Binks is my copilot'")
tokens.size.should == 1
tokens[0].size.should == 3
tokens[0][0].should == "set"
tokens[0][1].should == "/foo/JarJar"
tokens[0][2].should == "Binks is my copilot"
end
it "should accept spaces in the value and double ticks" do
- @resource.stubs(:[]).returns("/foo/")
+ @resource.stubs(:[]).returns("/foo/")
tokens = @provider.parse_commands('set /JarJar "Binks is my copilot"')
tokens.size.should == 1
tokens[0].size.should == 3
tokens[0][0].should == "set"
tokens[0][1].should == '/JarJar'
tokens[0][2].should == 'Binks is my copilot'
end
it "should accept mixed ticks" do
- @resource.stubs(:[]).returns("/foo/")
+ @resource.stubs(:[]).returns("/foo/")
tokens = @provider.parse_commands('set JarJar "Some \'Test\'"')
tokens.size.should == 1
tokens[0].size.should == 3
tokens[0][0].should == "set"
tokens[0][1].should == '/foo/JarJar'
tokens[0][2].should == "Some \'Test\'"
end
- it "should handle complex rm calls" do
- @resource.stubs(:[]).returns("/foo/")
+ it "should handle predicates with literals" do
+ @resource.stubs(:[]).returns("/foo/")
tokens = @provider.parse_commands("rm */*[module='pam_console.so']")
tokens.should == [["rm", "/foo/*/*[module='pam_console.so']"]]
end
- it "should handle insert with xpath queries" do
- @resource.stubs(:[]).returns("/foo/")
+ it "should handle whitespace in predicates" do
+ @resource.stubs(:[]).returns("/foo/")
tokens = @provider.parse_commands("ins 42 before /files/etc/hosts/*/ipaddr[ . = '127.0.0.1' ]")
- tokens.should == [["ins", "42", "before","/files/etc/hosts/*/ipaddr[ . = '127.0.0.1' ]"]]
+ tokens.should == [["ins", "42", "before","/files/etc/hosts/*/ipaddr[ . = '127.0.0.1' ]"]]
end
- it "should handle set with xpath queries" do
- @resource.stubs(:[]).returns("/foo/")
- tokens = @provider.parse_commands("set /files/etc/*/*[ipaddr = '127.0.0.1'] \"foo bar\"")
- tokens.should == [["set", "/files/etc/*/*[ipaddr = '127.0.0.1']", "foo bar"]]
+ it "should handle multiple predicates" do
+ @resource.stubs(:[]).returns("/foo/")
+ tokens = @provider.parse_commands("clear pam.d/*/*[module = 'system-auth'][type = 'account']")
+ tokens.should == [["clear", "/foo/pam.d/*/*[module = 'system-auth'][type = 'account']"]]
end
- it "should handle clear with xpath queries" do
- @resource.stubs(:[]).returns("/foo/")
- tokens = @provider.parse_commands("clear pam.d/*/*[module = 'system-auth'][type = 'account']")
- tokens.should == [["clear", "/foo/pam.d/*/*[module = 'system-auth'][type = 'account']"]]
+ it "should handle nested predicates" do
+ @resource.stubs(:[]).returns("/foo/")
+ args = ["clear", "/foo/pam.d/*/*[module[ ../type = 'type] = 'system-auth'][type[last()] = 'account']"]
+ tokens = @provider.parse_commands(args.join(" "))
+ tokens.should == [ args ]
end
- it "should handle some odd test" do
- @resource.stubs(:[]).returns("/foo/")
+ it "should handle escaped doublequotes in doublequoted string" do
+ @resource.stubs(:[]).returns("/foo/")
tokens = @provider.parse_commands("set /foo \"''\\\"''\"")
- tokens.should == [[ "set", "/foo", "''\\\"''" ]]
- end
+ tokens.should == [[ "set", "/foo", "''\\\"''" ]]
+ end
+
+ it "should allow escaped spaces and brackets in paths" do
+ @resource.stubs(:[]).returns("/foo/")
+ args = [ "set", "/white\\ space/\\[section", "value" ]
+ tokens = @provider.parse_commands(args.join(" \t "))
+ tokens.should == [ args ]
+ end
+
+ it "should remove trailing slashes" do
+ @resource.stubs(:[]).returns("/foo/")
+ tokens = @provider.parse_commands("set foo/ bar")
+ tokens.should == [[ "set", "/foo/foo", "bar" ]]
+ end
end
describe "get filters" do
before do
augeas_stub = stub("augeas", :get => "value")
@@ -176,36 +203,37 @@
command = ["match", "fake value", "include JarJar"]
@provider.process_match(command).should == false
end
it "should return true for an array match" do
- command = ["match", "fake value", "eq ['set', 'of', 'values']"]
+ command = ["match", "fake value", "== ['set', 'of', 'values']"]
@provider.process_match(command).should == true
end
it "should return false for an array non match" do
- command = ["match", "fake value", "eq ['this', 'should', 'not', 'match']"]
+ command = ["match", "fake value", "== ['this', 'should', 'not', 'match']"]
@provider.process_match(command).should == false
end
it "should return false for an array match with noteq" do
- command = ["match", "fake value", "noteq ['set', 'of', 'values']"]
+ command = ["match", "fake value", "!= ['set', 'of', 'values']"]
@provider.process_match(command).should == false
end
it "should return true for an array non match with noteq" do
- command = ["match", "fake value", "noteq ['this', 'should', 'not', 'match']"]
+ command = ["match", "fake value", "!= ['this', 'should', 'not', 'match']"]
@provider.process_match(command).should == true
- end
+ end
end
describe "need to run" do
it "should handle no filters" do
resource = stub("resource")
resource.stubs(:[]).returns(false).then.returns("").then.returns("")
augeas_stub = stub("augeas", :match => ["set", "of", "values"])
augeas_stub.stubs("close")
provider = provider_class.new(resource)
+ provider.aug= augeas_stub
provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == true
end
it "should return true when a get filter matches" do