summaryrefslogtreecommitdiff
path: root/puppet/modules/augeas/spec/unit
diff options
context:
space:
mode:
authorMicah <micah@leap.se>2016-07-12 16:46:07 -0400
committerMicah <micah@leap.se>2016-07-12 16:46:07 -0400
commit95374aacb857ed35c2fdfe6be7c0bfab86653963 (patch)
tree572645f7b8da9680d499f4380dcbab7e69575b69 /puppet/modules/augeas/spec/unit
parent4a11e48e397f1a7eb4c68a1dd1f9e3c5a11352f8 (diff)
git subrepo clone https://leap.se/git/puppet_augeas puppet/modules/augeas
subrepo: subdir: "puppet/modules/augeas" merged: "27e3359" upstream: origin: "https://leap.se/git/puppet_augeas" branch: "master" commit: "27e3359" git-subrepo: version: "0.3.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "1e79595" Change-Id: Ifa5c7daf3f1be1793c42f873a267b7498f5c6c0f
Diffstat (limited to 'puppet/modules/augeas/spec/unit')
-rw-r--r--puppet/modules/augeas/spec/unit/puppet/parser/functions/augeas_spec.rb83
1 files changed, 83 insertions, 0 deletions
diff --git a/puppet/modules/augeas/spec/unit/puppet/parser/functions/augeas_spec.rb b/puppet/modules/augeas/spec/unit/puppet/parser/functions/augeas_spec.rb
new file mode 100644
index 00000000..b34fa5b5
--- /dev/null
+++ b/puppet/modules/augeas/spec/unit/puppet/parser/functions/augeas_spec.rb
@@ -0,0 +1,83 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe 'the augeas function' do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should fail if the augeas feature is not present" do
+ Puppet.features.expects(:augeas?).returns(false)
+ expect { scope.function_augeas([]) }.to raise_error(Puppet::ParseError, /requires the augeas feature/)
+ end
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("augeas")).to eq("function_augeas")
+ end
+
+ context "when passing wrong arguments" do
+ before :each do
+ Puppet.features.stubs(:augeas?).returns(true)
+ end
+
+ it "should raise a ParseError if there are no arguments" do
+ expect { scope.function_augeas([]) }.to raise_error(Puppet::ParseError, /Wrong number of arguments/)
+ end
+
+ it "should raise a ParseError if content is not a string" do
+ expect { scope.function_augeas([['foo'], 'Fstab.lns', []]) }.to raise_error(Puppet::ParseError, /content must be a string/)
+ end
+
+ it "should raise a ParseError if lens is not a string" do
+ expect { scope.function_augeas(['foo', ['Fstab.lns'], []]) }.to raise_error(Puppet::ParseError, /lens must be a string/)
+ end
+
+ it "should raise a ParseError if changes is not an array" do
+ expect { scope.function_augeas(['foo', 'Fstab.lns', 'changes']) }.to raise_error(Puppet::ParseError, /changes must be an array/)
+ end
+ end
+
+ if Puppet.features.augeas?
+ context "when passing invalid input" do
+ it "should fail to parse input with lens" do
+ expect { scope.function_augeas(['foo', 'Fstab.lns', []]) }.to raise_error(Puppet::ParseError, /Failed to parse string with lens Fstab.lns:/)
+ end
+ end
+
+ context "when passing illegal changes" do
+ it "should fail to apply illegal change" do
+ expect { scope.function_augeas(["\n", 'Fstab.lns', ['foo bar']]) }.to raise_error(Puppet::ParseError, /Failed to apply change to tree/)
+ end
+ end
+
+ context "when generating an invalid tree" do
+ it "should fail to apply changes with wrong tree" do
+ expect { scope.function_augeas(["\n", 'Fstab.lns', ['set ./1/opt 3']]) }.to raise_error(Puppet::ParseError, /Failed to apply changes with lens Fstab.lns:/)
+ end
+ end
+
+ context "when applying valid changes" do
+ it "should remove the 3rd option" do
+ result = scope.function_augeas(["proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns', ['rm ./1/opt[3]']])
+ expect(result.class).to eq(String)
+ #result.should == "proc /proc proc nodev,noexec 0 0\n"
+ end
+
+ it "should set a 4th option" do
+ result = scope.function_augeas(["proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns', ['ins opt after ./1/opt[last()]', 'set ./1/opt[last()] nofoo']])
+ expect(result.class).to eq(String)
+ #result.should == "proc /proc proc nodev,noexec,nosuid,nofoo 0 0\n"
+ end
+ end
+
+ context "when using old libs" do
+ it "should not work with Augeas prior to 1.0.0" do
+ Augeas.any_instance.expects(:get).with('/augeas/version').returns('0.10.0')
+ expect { scope.function_augeas(["\n", 'Fstab.lns', []]) }.to raise_error(Puppet::ParseError, /requires Augeas 1\.0\.0/)
+ end
+
+ it "should not work with ruby-augeas prior to 0.5.0" do
+ Augeas.any_instance.expects(:methods).returns([])
+ expect { scope.function_augeas(["\n", 'Fstab.lns', []]) }.to raise_error(Puppet::ParseError, /requires ruby-augeas 0\.5\.0/)
+ end
+ end
+ end
+end