summaryrefslogtreecommitdiffstats
path: root/spec/unit/provider/augeas/augeas.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/provider/augeas/augeas.rb')
-rw-r--r--spec/unit/provider/augeas/augeas.rb77
1 files changed, 57 insertions, 20 deletions
diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb
index affc66676..284145657 100644
--- a/spec/unit/provider/augeas/augeas.rb
+++ b/spec/unit/provider/augeas/augeas.rb
@@ -133,14 +133,14 @@ describe provider_class do
tokens[0][0].should == "set"
tokens[0][1].should == 'Jar Jar'
tokens[0][2].should == "Binks is my copilot"
- end
+ end
end
describe "get filters" do
before do
augeas_stub = stub("augeas", :get => "value")
@provider = provider_class.new()
- @provider.stubs(:open_augeas).returns(augeas_stub)
+ @provider.aug= augeas_stub
end
it "should return false for a = nonmatch" do
@@ -168,7 +168,7 @@ describe provider_class do
before do
augeas_stub = stub("augeas", :match => ["set", "of", "values"])
@provider = provider_class.new()
- @provider.stubs(:open_augeas).returns(augeas_stub)
+ @provider.aug= augeas_stub
end
it "should return true for size match" do
@@ -202,53 +202,82 @@ describe provider_class do
end
end
- describe "need_to_run" do
+ describe "need to run" do
it "should handle no filters" do
- resource = stub("resource", :[] => "")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("")
+ augeas_stub = stub("augeas", :match => ["set", "of", "values"])
+ augeas_stub.stubs("close")
provider = provider_class.new(resource)
+ 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
- resource = stub("resource", :[] => "get path == value")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("get path == value")
provider = provider_class.new(resource)
augeas_stub = stub("augeas", :get => "value")
- provider.stubs(:open_augeas).returns(augeas_stub)
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == true
end
it "should return false when a get filter does not match" do
- resource = stub("resource", :[] => "get path == another value")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("get path == another value")
provider = provider_class.new(resource)
augeas_stub = stub("augeas", :get => "value")
- provider.stubs(:open_augeas).returns(augeas_stub)
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == false
end
it "should return true when a match filter matches" do
- resource = stub("resource", :[] => "match path size == 3")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("match path size == 3")
provider = provider_class.new(resource)
augeas_stub = stub("augeas", :match => ["set", "of", "values"])
- provider.stubs(:open_augeas).returns(augeas_stub)
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == true
end
it "should return false when a match filter does not match" do
- resource = stub("resource", :[] => "match path size == 2")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("match path size == 2")
+ provider = provider_class.new(resource)
+ augeas_stub = stub("augeas", :match => ["set", "of", "values"])
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
+ provider.need_to_run?.should == false
+ end
+
+ #This is a copy of the last one, with setting the force to true
+ it "setting force should not change the above logic" do
+ resource = stub("resource")
+ resource.stubs(:[]).returns(true).then.returns("match path size == 2")
provider = provider_class.new(resource)
augeas_stub = stub("augeas", :match => ["set", "of", "values"])
- provider.stubs(:open_augeas).returns(augeas_stub)
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == false
end
end
- describe "augeas integration" do
+ describe "augeas execution integration" do
before do
@resource = stub("resource")
@provider = provider_class.new(@resource)
@augeas = stub("augeas")
- @provider.stubs(:open_augeas).returns(@augeas)
+ @provider.aug= @augeas
+ @provider.stubs(:get_augeas_version).returns("0.3.5")
end
it "should handle set commands" do
@@ -257,6 +286,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:set).with("/some/path/Jar/Jar", "Binks")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -266,6 +296,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:rm).with("/Jar/Jar")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -275,6 +306,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:rm).with("/Jar/Jar")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -284,9 +316,10 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:clear).with("/foo/Jar/Jar")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
- end
-
+ end
+
it "should handle ins commands with before" do
command = [["ins", "Binks", "before /Jar/Jar"]]
@@ -294,6 +327,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", true)
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -303,6 +337,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false)
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -312,16 +347,18 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/Jar/Jar", "Binks", false)
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
- end
-
+ end
+
it "should handle multiple commands" do
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)
- @augeas.expects(:clear).with("/foo/Jar/Jar")
+ @augeas.expects(:clear).with("/foo/Jar/Jar")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
end