summaryrefslogtreecommitdiff
path: root/spec/unit/puppet
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-05-21 22:03:04 +0200
committerGuido Günther <agx@sigxcpu.org>2014-05-22 21:52:11 +0200
commit6b9bc57547e7bc84b17f33a4807f22be6bf91ecb (patch)
treebf2ceb234c0ac842c752222cc5f17a1978390457 /spec/unit/puppet
parentc4abfdae1bcc4f24606467e43b738cc412f98741 (diff)
Add validate_nonemptystring_msg
This allows to print a custom message when the string is not valid but only accepts a single argument.
Diffstat (limited to 'spec/unit/puppet')
-rw-r--r--spec/unit/puppet/parser/functions/validate_nonemptystring_msg_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/unit/puppet/parser/functions/validate_nonemptystring_msg_spec.rb b/spec/unit/puppet/parser/functions/validate_nonemptystring_msg_spec.rb
new file mode 100644
index 0000000..47988e4
--- /dev/null
+++ b/spec/unit/puppet/parser/functions/validate_nonemptystring_msg_spec.rb
@@ -0,0 +1,52 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_nonemptystring_msg) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling validate_nonemptystring_msg from puppet' do
+
+ it "should compile when foo is a string" do
+ Puppet[:code] = "validate_nonemptystring_msg('foo', 'a msg')"
+ scope.compiler.compile
+ end
+
+
+ %w{ true false }.each do |the_string|
+ it "should compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_nonemptystring_msg('#{the_string}', 'a msg')"
+ scope.compiler.compile
+ end
+
+ it "should not compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_nonemptystring_msg(#{the_string}, 'a msg')"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /msg/)
+ end
+ end
+
+ it "should not compile when an explicitly undef variable is passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = undef
+ validate_nonemptystring_msg($foo, 'a msg')
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /msg/)
+ end
+
+ it "should not compile when an undefined variable is passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ validate_nonemptystring_msg($foobarbazishouldnotexist, 'a msg')
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /msg/)
+ end
+
+ it "should not compile when the string is empty" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $bar = ''
+ validate_nonemptystring_msg($bar, 'a msg')
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /msg/)
+ end
+
+ end
+end